summaryrefslogtreecommitdiff
path: root/cache/cache_test.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-22 18:29:37 +0200
committerewy <ewy0@protonmail.com>2026-04-22 18:29:37 +0200
commit374ed5e1a4dc635c42e33e4133729d40cf3e0e35 (patch)
tree01f12ca3eea0154b61afde3d1ee27df2094644e1 /cache/cache_test.go
parentee481fa406bb685a16d8b568fca0c9f592c06180 (diff)
work on tests
also replace the annoying search return with a struct
Diffstat (limited to 'cache/cache_test.go')
-rw-r--r--cache/cache_test.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/cache/cache_test.go b/cache/cache_test.go
index c140154..499c0f5 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -10,7 +10,7 @@ func TestFromReader_Blank(t *testing.T) {
input := `
`
sr := strings.NewReader(input)
- c, err := FromReader(sr)
+ c, err := Load(sr)
assert.Nil(t, err)
assert.Len(t, c.Entries, 0)
}
@@ -18,7 +18,7 @@ func TestFromReader_Blank(t *testing.T) {
func TestFromReader_OneEntry(t *testing.T) {
input := `/abc/def # deffers`
sr := strings.NewReader(input)
- c, err := FromReader(sr)
+ c, err := Load(sr)
assert.Nil(t, err)
assert.Len(t, c.Entries, 1)
assert.Equal(t, c.Entries[0], Entry{
@@ -33,7 +33,7 @@ func TestFromReader_ManyEntries(t *testing.T) {
/path/src # da source
`
sr := strings.NewReader(input)
- c, err := FromReader(sr)
+ c, err := Load(sr)
assert.Nil(t, err)
assert.Len(t, c.Entries, 3)
assert.Equal(t, c.Entries[0], Entry{
@@ -61,7 +61,7 @@ func TestFromReader_Comments(t *testing.T) {
# // comment
`
sr := strings.NewReader(input)
- c, err := FromReader(sr)
+ c, err := Load(sr)
assert.Nil(t, err)
assert.Len(t, c.Entries, 3)
assert.Equal(t, c.Entries[0], Entry{
@@ -91,3 +91,25 @@ func TestStrip_Nothing(t *testing.T) {
result := c.Strip(old)
assert.Equal(t, c, result)
}
+
+func TestMerge(t *testing.T) {
+ a := Entry{
+ Path: "/usr/share/asdf",
+ }
+ b := Entry{
+ Path: "/test/location",
+ }
+ c := Entry{
+ Path: "/new/mypath",
+ Label: "mypath",
+ }
+ base := Cache{Entries: []Entry{
+ a, b,
+ }}
+ other := Cache{Entries: []Entry{
+ b, c,
+ }}
+ result := base.Merge(other)
+ assert.Len(t, result.Entries, 3)
+ assert.Contains(t, result.Entries, a, b, c)
+}