mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-25 13:31:21 +00:00
Fix: Tests broken after last change
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ddaaf041d9
commit
59906b06e8
1 changed files with 22 additions and 22 deletions
|
@ -25,39 +25,39 @@ func TestWatcherCheckHash(t *testing.T) {
|
||||||
w, err := newWatcher(testFile, time.Second, WatcherCheckHash(sha256.New))
|
w, err := newWatcher(testFile, time.Second, WatcherCheckHash(sha256.New))
|
||||||
require.NoError(t, err, "initial check should not error on non existing file")
|
require.NoError(t, err, "initial check should not error on non existing file")
|
||||||
|
|
||||||
evt, err := w.runStateChecks(false)
|
evt, err := w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
||||||
require.NoError(t, err, "creating test file")
|
require.NoError(t, err, "creating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file now exists and has hash change")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file now exists and has hash change")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same hash")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same hash")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file was modified")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file was modified")
|
||||||
|
|
||||||
err = os.Remove(testFile)
|
err = os.Remove(testFile)
|
||||||
require.NoError(t, err, "deleting test file")
|
require.NoError(t, err, "deleting test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect change as file has same hash")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect change as file has same hash")
|
||||||
}
|
}
|
||||||
|
@ -76,18 +76,18 @@ func TestWatcherCheckMtime(t *testing.T) {
|
||||||
w, err := newWatcher(testFile, time.Second, WatcherCheckMtime)
|
w, err := newWatcher(testFile, time.Second, WatcherCheckMtime)
|
||||||
require.NoError(t, err, "initial check should not error on non existing file")
|
require.NoError(t, err, "initial check should not error on non existing file")
|
||||||
|
|
||||||
evt, err := w.runStateChecks(false)
|
evt, err := w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
||||||
require.NoError(t, err, "creating test file")
|
require.NoError(t, err, "creating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file now exists and has mtime change")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file now exists and has mtime change")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same mtime")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same mtime")
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ func TestWatcherCheckMtime(t *testing.T) {
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file was modified")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file was modified")
|
||||||
|
|
||||||
err = os.Remove(testFile)
|
err = os.Remove(testFile)
|
||||||
require.NoError(t, err, "deleting test file")
|
require.NoError(t, err, "deleting test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func TestWatcherCheckMtime(t *testing.T) {
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file is newer")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file is newer")
|
||||||
}
|
}
|
||||||
|
@ -131,25 +131,25 @@ func TestWatcherCheckPresence(t *testing.T) {
|
||||||
w, err := newWatcher(testFile, time.Second, WatcherCheckPresence)
|
w, err := newWatcher(testFile, time.Second, WatcherCheckPresence)
|
||||||
require.NoError(t, err, "initial check should not error on non existing file")
|
require.NoError(t, err, "initial check should not error on non existing file")
|
||||||
|
|
||||||
evt, err := w.runStateChecks(false)
|
evt, err := w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as file is still missing")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as file is still missing")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
||||||
require.NoError(t, err, "creating test file")
|
require.NoError(t, err, "creating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileAppeared, evt, "expect check to state file is now there")
|
assert.Equal(t, WatcherEventFileAppeared, evt, "expect check to state file is now there")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect check to state nothing changed")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect check to state nothing changed")
|
||||||
|
|
||||||
err = os.Remove(testFile)
|
err = os.Remove(testFile)
|
||||||
require.NoError(t, err, "deleting test file")
|
require.NoError(t, err, "deleting test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventFileVanished, evt, "expect check to state file vanished again")
|
assert.Equal(t, WatcherEventFileVanished, evt, "expect check to state file vanished again")
|
||||||
}
|
}
|
||||||
|
@ -168,42 +168,42 @@ func TestWatcherCheckSize(t *testing.T) {
|
||||||
w, err := newWatcher(testFile, time.Second, WatcherCheckSize)
|
w, err := newWatcher(testFile, time.Second, WatcherCheckSize)
|
||||||
require.NoError(t, err, "initial check should not error on non existing file")
|
require.NoError(t, err, "initial check should not error on non existing file")
|
||||||
|
|
||||||
evt, err := w.runStateChecks(false)
|
evt, err := w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect invalid as file is still missing")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
err = os.WriteFile(testFile, []byte("test"), 0o644)
|
||||||
require.NoError(t, err, "creating test file")
|
require.NoError(t, err, "creating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file has now 4 instead of 0 bytes")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as file has now 4 instead of 0 bytes")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("tset"), 0o644)
|
err = os.WriteFile(testFile, []byte("tset"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same size")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as the file has the same size")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventFileModified, evt, "expect change as we went from 4 to 11 chars")
|
assert.Equal(t, WatcherEventFileModified, evt, "expect change as we went from 4 to 11 chars")
|
||||||
|
|
||||||
err = os.Remove(testFile)
|
err = os.Remove(testFile)
|
||||||
require.NoError(t, err, "deleting test file")
|
require.NoError(t, err, "deleting test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on non existing file")
|
require.NoError(t, err, "check should not error on non existing file")
|
||||||
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
assert.Equal(t, WatcherEventInvalid, evt, "expect check to be invalid as file is no longer there")
|
||||||
|
|
||||||
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
err = os.WriteFile(testFile, []byte("hello world"), 0o644)
|
||||||
require.NoError(t, err, "updating test file")
|
require.NoError(t, err, "updating test file")
|
||||||
|
|
||||||
evt, err = w.runStateChecks(false)
|
evt, err = w.runStateChecks()
|
||||||
require.NoError(t, err, "check should not error on existing file")
|
require.NoError(t, err, "check should not error on existing file")
|
||||||
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as we restored the file with same content")
|
assert.Equal(t, WatcherEventNoChange, evt, "expect no change as we restored the file with same content")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue