github.com/grahambrereton-form3/tilt@v0.10.18/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/windmilleng/tilt/internal/testutils/tempdir"
     9  )
    10  
    11  func TestNewRelativeFileOrChildMatcher(t *testing.T) {
    12  	f := tempdir.NewTempDirFixture(t)
    13  	defer f.TearDown()
    14  
    15  	paths := []string{
    16  		"a",
    17  		"b/c/d",
    18  		"/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  		"/already/abs":      true,
    26  	}
    27  
    28  	assert.Equal(t, expected, matcher.paths)
    29  }
    30  
    31  func TestFileOrChildMatcher(t *testing.T) {
    32  	f := tempdir.NewTempDirFixture(t)
    33  	defer f.TearDown()
    34  
    35  	matcher := fileOrChildMatcher{map[string]bool{
    36  		"file.txt":        true,
    37  		"nested/file.txt": true,
    38  		"directory":       true,
    39  	}}
    40  
    41  	// map test case --> expected match
    42  	expectedMatch := map[string]bool{
    43  		"file.txt":                true,
    44  		"nested/file.txt":         true,
    45  		"nested":                  false,
    46  		"nested/otherfile.txt":    false,
    47  		"directory/some/file.txt": true,
    48  		"other/dir/entirely":      false,
    49  	}
    50  
    51  	for f, expected := range expectedMatch {
    52  		match, err := matcher.Matches(f)
    53  		if assert.NoError(t, err) {
    54  			assert.Equal(t, expected, match, "expected file '%s' match --> %t", f, expected)
    55  		}
    56  	}
    57  }