github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/deployment/internal/ignore/ignore_test.go (about) 1 package ignore 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 ) 8 9 var Matches = []string{ 10 ".DS_Store", 11 "/.DS_Store", 12 "/foo/bar/.DS_Store", 13 ".swp", 14 "/foo/bar/.swp", 15 "/foo/bar/_swp", 16 "/foo/bar/_swp", 17 "/foo/bar/.kdev4", 18 } 19 20 var NoMatches = []string{ 21 "file", 22 "swp.swp", 23 "swp.swp", 24 "/foo/DS_Store", 25 "DS_Store", // missing "." 26 } 27 28 func TestMatch(t *testing.T) { 29 for _, m := range Matches { 30 if !Match(m) { 31 t.Errorf("Expected %v to be matched.", m) 32 } 33 } 34 35 for _, nm := range NoMatches { 36 if Match(nm) { 37 t.Errorf("Expected %v to not be matched.", nm) 38 } 39 } 40 } 41 42 type walker struct { 43 b *testing.B 44 } 45 46 func (w *walker) walkFn(path string, info os.FileInfo, err error) error { 47 if err != nil { 48 return err 49 } 50 51 path, _ = filepath.Abs(path) 52 _ = Match(path) 53 54 return nil 55 } 56 57 func BenchmarkMatchRepository(b *testing.B) { 58 // Remind that the tendency of any repo is to grow. 59 // Therefore, comparing benchmark generated at different times 60 // is futile. Instead, focus on comparing different algorithms against the same data. 61 var w = walker{b} 62 63 for i := 0; i < b.N; i++ { 64 if err := filepath.Walk("../../", w.walkFn); err != nil { 65 b.Errorf("Error walking: %v", err) 66 } 67 } 68 }