github.com/mkasner/goat@v0.0.0-20190419083224-77b17249a8e3/context/watcher_test.go (about)

     1  package context
     2  
     3  import "testing"
     4  
     5  func TestExcludeDir(t *testing.T) {
     6  	testData := []struct {
     7  		excludes []string
     8  		dirname  string
     9  		exclude  bool
    10  	}{
    11  		{
    12  			excludes: []string{"a/", "b/*"},
    13  			dirname:  "/n/p/a",
    14  			exclude:  true,
    15  		},
    16  		{
    17  			excludes: []string{"a/", "b/*"},
    18  			dirname:  "/n/p/b",
    19  			exclude:  true,
    20  		},
    21  		{
    22  			excludes: []string{"a/", "b/*"},
    23  			dirname:  "/n/p/c",
    24  			exclude:  false,
    25  		},
    26  		{
    27  			excludes: []string{"a/", "../../b/*"},
    28  			dirname:  "/n/p/../../b",
    29  			exclude:  true,
    30  		},
    31  	}
    32  	for i, td := range testData {
    33  		w := Watcher{
    34  			Excludes: td.excludes,
    35  		}
    36  		exclude := w.excludeDir(td.dirname)
    37  		if td.exclude != exclude {
    38  			t.Fatalf("[%d] exp: %t got: %t", i, td.exclude, exclude)
    39  		}
    40  	}
    41  }