| 90 | } |
| 91 | |
| 92 | func TestWalkSub(t *testing.T) { |
| 93 | testFs := newTestFs() |
| 94 | ignores := ignore.New(testFs) |
| 95 | err := ignores.Load(".stignore") |
| 96 | if err != nil { |
| 97 | t.Fatal(err) |
| 98 | } |
| 99 | |
| 100 | cfg, cancel := testConfig() |
| 101 | defer cancel() |
| 102 | cfg.Subs = []string{"dir2"} |
| 103 | cfg.Matcher = ignores |
| 104 | fchan := Walk(context.TODO(), cfg) |
| 105 | var files []protocol.FileInfo |
| 106 | for f := range fchan { |
| 107 | if f.Err != nil { |
| 108 | t.Errorf("Error while scanning %v: %v", f.Err, f.Path) |
| 109 | } |
| 110 | files = append(files, f.File) |
| 111 | } |
| 112 | |
| 113 | // The directory contains two files, where one is ignored from a higher |
| 114 | // level. We should see only the directory and one of the files. |
| 115 | |
| 116 | if len(files) != 2 { |
| 117 | t.Fatalf("Incorrect length %d != 2", len(files)) |
| 118 | } |
| 119 | if files[0].Name != "dir2" { |
| 120 | t.Errorf("Incorrect file %v != dir2", files[0]) |
| 121 | } |
| 122 | if files[1].Name != filepath.Join("dir2", "cfile") { |
| 123 | t.Errorf("Incorrect file %v != dir2/cfile", files[1]) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func TestWalk(t *testing.T) { |
| 128 | testFs := newTestFs() |