summaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-22 19:27:25 +0200
committerewy <ewy0@protonmail.com>2026-04-22 19:29:16 +0200
commit5e1e840bbcdf8348ae62145e1b7231764fcc5a97 (patch)
treedad5d223dc95b643febde31c45beb2d68110aa9c /cache
parentf13b2bcf9a3a5ea6afeaa60c7a2e801e8e79a2c1 (diff)
update script experiment
Diffstat (limited to 'cache')
-rw-r--r--cache/cache.go8
-rw-r--r--cache/cache_test.go52
2 files changed, 52 insertions, 8 deletions
diff --git a/cache/cache.go b/cache/cache.go
index 8a17592..f036052 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -143,11 +143,3 @@ outer:
Entries: result,
}
}
-
-func Touch() error {
- fd, err := os.Create(Path)
- if fd != nil {
- defer fd.Close()
- }
- return err
-}
diff --git a/cache/cache_test.go b/cache/cache_test.go
index 499c0f5..38c100a 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -1,11 +1,37 @@
+//go:build test
+
package cache
import (
"github.com/stretchr/testify/assert"
+ . "pik/testx"
"strings"
"testing"
+ "testing/fstest"
)
+func TestLoadFile(t *testing.T) {
+ input := `
+
+# comment
+/asdf/hjkl # label
+
+# other comment
+//comment
+
+`
+ f := fstest.MapFS{
+ "contexts": &fstest.MapFile{
+ Data: []byte(input),
+ },
+ }
+ res, err := LoadFile(f, "contexts")
+ assert.NoError(t, err)
+ assert.Len(t, res.Entries, 1)
+ assert.Equal(t, res.Entries[0].Path, "/asdf/hjkl")
+ assert.Equal(t, res.Entries[0].Label, "label")
+}
+
func TestFromReader_Blank(t *testing.T) {
input := `
`
@@ -113,3 +139,29 @@ func TestMerge(t *testing.T) {
assert.Len(t, result.Entries, 3)
assert.Contains(t, result.Entries, a, b, c)
}
+
+func TestCache_String(t *testing.T) {
+ c := Cache{Entries: []Entry{{Path: "/asdf/hjkl", Label: "hjkl"}}}
+ output := c.String()
+ for _, e := range c.Entries {
+ assert.Contains(t, output, e.Path)
+ assert.Contains(t, output, e.Label)
+ }
+}
+
+func TestNew(t *testing.T) {
+ st := TState(TSource("/test/location", "target1", "target2"), TSource("/other/place/asdf/hjkl", "1target", "2target"))
+ c := New(st)
+ assert.NotNil(t, c)
+ assert.Len(t, c.Entries, 2)
+ assert.Equal(t, "/test/location", c.Entries[0].Path)
+ assert.Equal(t, "/other/place/asdf/hjkl", c.Entries[1].Path)
+}
+
+func TestLoadFile_NotExist(t *testing.T) {
+ f := fstest.MapFS{}
+ c, err := LoadFile(f, "anything is fine")
+ assert.Nil(t, c.Entries)
+ assert.Error(t, err)
+
+}