TestWatchWinRoot checks that a watch at a drive letter does not panic due to out of root event on every event. https://github.com/syncthing/syncthing/issues/5695
(t *testing.T)
| 155 | // out of root event on every event. |
| 156 | // https://github.com/syncthing/syncthing/issues/5695 |
| 157 | func TestWatchWinRoot(t *testing.T) { |
| 158 | if !build.IsWindows { |
| 159 | t.Skip("Windows specific test") |
| 160 | } |
| 161 | |
| 162 | outChan := make(chan Event) |
| 163 | backendChan := make(chan notify.EventInfo, backendBuffer) |
| 164 | errChan := make(chan error) |
| 165 | |
| 166 | ctx, cancel := context.WithCancel(context.Background()) |
| 167 | |
| 168 | // testFs is Filesystem, but we need BasicFilesystem here |
| 169 | root := `D:\` |
| 170 | fs := newBasicFilesystem(root) |
| 171 | watch, roots, err := fs.watchPaths(".") |
| 172 | if err != nil { |
| 173 | t.Fatal(err) |
| 174 | } |
| 175 | |
| 176 | done := make(chan struct{}) |
| 177 | defer func() { |
| 178 | cancel() |
| 179 | <-done |
| 180 | }() |
| 181 | go func() { |
| 182 | defer func() { |
| 183 | if r := recover(); r != nil { |
| 184 | t.Error(r) |
| 185 | } |
| 186 | cancel() |
| 187 | }() |
| 188 | fs.watchLoop(ctx, ".", roots, backendChan, outChan, errChan, fakeMatcher{}) |
| 189 | close(done) |
| 190 | }() |
| 191 | |
| 192 | // filepath.Dir as watch has a /... suffix |
| 193 | name := "foo" |
| 194 | backendChan <- fakeEventInfo(filepath.Join(filepath.Dir(watch), name)) |
| 195 | |
| 196 | select { |
| 197 | case <-time.After(10 * time.Second): |
| 198 | cancel() |
| 199 | t.Errorf("Timed out before receiving event") |
| 200 | case ev := <-outChan: |
| 201 | if ev.Name != name { |
| 202 | t.Errorf("Unexpected event %v, expected %v", ev.Name, name) |
| 203 | } |
| 204 | case err := <-errChan: |
| 205 | t.Error("Received fatal watch error:", err) |
| 206 | case <-ctx.Done(): |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // TestWatchOutside checks that no changes from outside the folder make it in |
| 211 | func TestWatchOutside(t *testing.T) { |
nothing calls this directly
no test coverage detected