]> go.fuhry.dev Git - fsnotify.git/commit
Rewrite tests (#478)
authorMartin Tournoij <martin@arp242.net>
Sun, 31 Jul 2022 18:03:10 +0000 (20:03 +0200)
committerGitHub <noreply@github.com>
Sun, 31 Jul 2022 18:03:10 +0000 (20:03 +0200)
commit87dc1faa3281067e32fee8a752e9109289b9e341
tree156589675e99687f5efd2a82f0afcbb9d8098fca
parent57e6a492ad52980fc388256312c67e5b810a6e6f
Rewrite tests (#478)

Rewrite tests

This rewrites quite a lot of tests to be much more easily readable.

While working on #472 I wanted to check "how do renames behave now?",
and found this quite hard as most test cases were >90% "plumbing", and
seeing "what file operations does this do?" and "what events do we get?"
was not very easy.

So refactor the lot, based on some work I did in #472:

- Add a bunch of "shell-like" helper functions so you're not forever
  typing error checks, filepath.Join(), and eventSeparator(). Just
  touch(t, tmp, "file") will create a file in tmp.

- Add eventCollector type which will collect all events in in a slice,
  replacing the previous "counter". This also ensures that the Watcher
  is closed within a second (this removes a lot of duplicate code).

  This is also much more precise than merely counting events; before
  random events could get emitted but if you weren't counting those then
  you'd never know.

  Downside is that some tests are a bit more flaky now as some
  behaviours are not always consistent in various edge cases; these are
  pre-existing bugs.

- Add Events (plural) type (only for tests), and helper function to
  create this from a string like:

      REMOVE  /link
      CREATE  /link
      WRITE   /link

  Which makes seeing which events are received, diffing them, etc. much
  easier.

- Add Parallel() for most tests; reduces runtime on my system from ~12
  seconds to ~6 seconds.

All in all it reduces the integrations_test.go from 1279 lines to 405
lines and it's quite easy to see which events are expected for which
operations, which should make things a lot easier going forward.
fsnotify.go
fsnotify_test.go
helpers_test.go [new file with mode: 0644]
inotify.go
inotify_test.go
integration_darwin_test.go
integration_test.go
kqueue.go