diff --git a/internal/dirwatch/dirwatch_internal_test.go b/internal/dirwatch/dirwatch_internal_test.go index 03a9dab..bd0d8c1 100644 --- a/internal/dirwatch/dirwatch_internal_test.go +++ b/internal/dirwatch/dirwatch_internal_test.go @@ -15,6 +15,15 @@ import ( // errWatch is an error the watch reports. var errWatch = errors.New("too many changes") +func TestDirectoryThatCannotBeWatchedIsAnError(t *testing.T) { + t.Parallel() + + _, err := New(filepath.Join(t.TempDir(), "missing")) + if err == nil { + t.Error("a missing directory is watched, want an error") + } +} + // The tests below run callWhenQuiet in a synctest bubble, where time is a // clock of the test's own: time.Sleep moves it on at once, and // synctest.Wait returns once callWhenQuiet waits again, so that every call @@ -107,15 +116,6 @@ func TestErrorsOfTheWatchHandedOn(t *testing.T) { }) } -func TestDirectoryThatCannotBeWatchedIsAnError(t *testing.T) { - t.Parallel() - - _, err := New(filepath.Join(t.TempDir(), "missing")) - if err == nil { - t.Error("a missing directory is watched, want an error") - } -} - // loop is a callWhenQuiet that a test runs. type loop struct { // changes and errs send it changes and errors. diff --git a/internal/lookup/file_internal_test.go b/internal/lookup/file_internal_test.go index 4e3bbac..f38fdcd 100644 --- a/internal/lookup/file_internal_test.go +++ b/internal/lookup/file_internal_test.go @@ -131,6 +131,31 @@ func TestFileThatCannotBeReadIsAnError(t *testing.T) { } } +func TestChangeOfAnotherFileInTheDirectoryIsNoReplacement(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + path := filepath.Join(dir, "ipinfo_lite.mmdb") + writeDatabase(t, path, "DE") + + f := openFile(t, path, newQueue()) + + for changed, want := range map[string]bool{ + path: true, + dir + "/./ipinfo_lite.mmdb": true, + filepath.Join(dir, "other.mmdb"): false, + } { + if f.isDatabase(changed) != want { + t.Errorf( + "a change to %s counts: %t, want %t", + changed, + !want, + want, + ) + } + } +} + // The tests below run in a synctest bubble, where time is a clock of the // test's own, so that the time a file is read can be checked. The wait for // the directory to go quiet before a reading is tested in dirwatch. @@ -202,31 +227,6 @@ func TestReplacementThatCannotBeReadLeavesTheFileInUseWithOneAlert( }) } -func TestChangeOfAnotherFileInTheDirectoryIsNoReplacement(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - path := filepath.Join(dir, "ipinfo_lite.mmdb") - writeDatabase(t, path, "DE") - - f := openFile(t, path, newQueue()) - - for changed, want := range map[string]bool{ - path: true, - dir + "/./ipinfo_lite.mmdb": true, - filepath.Join(dir, "other.mmdb"): false, - } { - if f.isDatabase(changed) != want { - t.Errorf( - "a change to %s counts: %t, want %t", - changed, - !want, - want, - ) - } - } -} - // newQueue returns a queue of alerts for a webhook that is never sent // them, so that they wait in it for the test to look at. func newQueue() *alerts.Queue {