github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/model/matcher_test.go (about) 1 package model 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/tilt-dev/tilt/internal/ospath" 9 "github.com/tilt-dev/tilt/internal/testutils/tempdir" 10 ) 11 12 func TestNewRelativeFileOrChildMatcher(t *testing.T) { 13 f := tempdir.NewTempDirFixture(t) 14 15 paths := []string{ 16 "a", 17 "b/c/d", 18 ospath.MustAbs("already/abs"), 19 } 20 matcher := NewRelativeFileOrChildMatcher(f.Path(), paths...) 21 22 expected := map[string]bool{ 23 f.JoinPath("a"): true, 24 f.JoinPath("b/c/d"): true, 25 ospath.MustAbs("already/abs"): true, 26 } 27 28 assert.Equal(t, expected, matcher.paths) 29 } 30 31 func TestFileOrChildMatcher(t *testing.T) { 32 matcher := fileOrChildMatcher{map[string]bool{ 33 "file.txt": true, 34 "nested/file.txt": true, 35 "directory": true, 36 }} 37 38 // map test case --> expected match 39 expectedMatch := map[string]bool{ 40 "file.txt": true, 41 "nested/file.txt": true, 42 "nested": false, 43 "nested/otherfile.txt": false, 44 "directory/some/file.txt": true, 45 "other/dir/entirely": false, 46 } 47 48 for f, expected := range expectedMatch { 49 match, err := matcher.Matches(f) 50 if assert.NoError(t, err) { 51 assert.Equal(t, expected, match, "expected file '%s' match --> %t", f, expected) 52 } 53 } 54 }