diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-22 20:44:06 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-22 20:44:06 +0200 |
| commit | 086a0cc0eb75c0c3a15cf6a715427df1e2d589a2 (patch) | |
| tree | 0bcc881b202f94a7ea39f94f13aea89ca2046312 /crawl | |
| parent | c6a362a039b1662dfc0badeb8badc4458e446787 (diff) | |
slowly working on that test coverage
Diffstat (limited to 'crawl')
| -rw-r--r-- | crawl/crawl.go | 6 | ||||
| -rw-r--r-- | crawl/crawl_test.go | 39 |
2 files changed, 37 insertions, 8 deletions
diff --git a/crawl/crawl.go b/crawl/crawl.go index dac6b19..fccd81d 100644 --- a/crawl/crawl.go +++ b/crawl/crawl.go @@ -16,12 +16,8 @@ func RichLocations(origin string) []string { eval, err := Evaluated(origin) if err == nil && eval != origin { - i := 0 evaledLocations := Locations(eval) - var result []string - for i < len(locs) && i < len(evaledLocations) { - result = append(result, evaledLocations[i], locs[i]) - } + result := append(locs, evaledLocations...) result = slices.Compact(result) return result } diff --git a/crawl/crawl_test.go b/crawl/crawl_test.go index 88b70f1..27fc0e8 100644 --- a/crawl/crawl_test.go +++ b/crawl/crawl_test.go @@ -1,8 +1,12 @@ +//go:build test + package crawl import ( "github.com/stretchr/testify/assert" - "io/fs" + "os" + "path/filepath" + "strings" "testing" ) @@ -53,6 +57,35 @@ func TestLocations_HighestFirst(t *testing.T) { assert.Equal(t, locs[0], "/one/two/three") } -func Test(t *testing.T) { - assert.True(t, fs.ValidPath("asdf/hjkl")) +func TestRichLocations(t *testing.T) { + dir := t.TempDir() + targetPath := filepath.Join(dir, "target") + linkPath := filepath.Join(dir, "link") + + innerPath := filepath.Join(targetPath, "inner") + innerLinkPath := filepath.Join(linkPath, "inner") + err := os.Mkdir(targetPath, 0777) + assert.NoError(t, err) + err = os.Symlink(targetPath, linkPath) + assert.NoError(t, err) + err = os.Mkdir(innerPath, 0777) + result := RichLocations(innerLinkPath) + assert.NotNil(t, result) + var hasLink, hasTarget = false, false + for _, e := range result { + if strings.HasSuffix(e, "target/inner") { + hasTarget = true + continue + } + if strings.HasSuffix(e, "link/inner") { + hasLink = true + continue + } + } + if !hasLink { + t.Fatal("evaluated link subdirectories were not included") + } + if !hasTarget { + t.Fatal("original target subdirectories were not included") + } } |
