X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=main_test.go;h=35845371f6878e7a44c0de11ad58b8390da48916;hb=d946c291618d93e4ab4ad898c1ae317fbe2256e3;hp=c4afa7929dbf980489cdde2fa487725d6f4917f1;hpb=5f90bfd1ae2fb737d14532d74d93e3f1c1763f99;p=nsscash%2Fnsscash.git diff --git a/main_test.go b/main_test.go index c4afa79..3584537 100644 --- a/main_test.go +++ b/main_test.go @@ -156,8 +156,8 @@ func mustMakeOld(t *testing.T, paths ...string) { } } -// mustMakeOld verifies that all paths have a modification time in the past, -// as set by mustMakeOld(). +// mustBeOld verifies that all paths have a modification time in the past, as +// set by mustMakeOld. func mustBeOld(t *testing.T, paths ...string) { for _, p := range paths { i, err := os.Stat(p) @@ -166,8 +166,7 @@ func mustBeOld(t *testing.T, paths ...string) { } mtime := i.ModTime() - now := time.Now() - if now.Sub(mtime) < time.Hour { + if time.Since(mtime) < time.Hour { t.Errorf("%q was recently modified", p) } } @@ -182,8 +181,7 @@ func mustBeNew(t *testing.T, paths ...string) { } mtime := i.ModTime() - now := time.Now() - if now.Sub(mtime) > time.Hour { + if time.Since(mtime) > time.Hour { t.Errorf("%q was not recently modified", p) } } @@ -327,7 +325,7 @@ func fetchPasswd404(a args) { "status code 404") mustNotExist(t, statePath, plainPath, groupPath) - mustBeOld(a.t, passwdPath) + mustBeOld(t, passwdPath) } func fetchPasswdUnexpected304(a args) { @@ -345,7 +343,7 @@ func fetchPasswdUnexpected304(a args) { "status code 304 but did not send If-Modified-Since") mustNotExist(t, statePath, plainPath, groupPath) - mustBeOld(a.t, passwdPath) + mustBeOld(t, passwdPath) } func fetchPasswdEmpty(a args) { @@ -715,6 +713,7 @@ func fetchStateCannotRead(a args) { statePath+": permission denied") mustNotExist(t, passwdPath, plainPath, groupPath) + mustBeOld(t, statePath) } func fetchStateInvalid(a args) { @@ -889,7 +888,7 @@ password = "%[6]s" err = mainFetch(configPath) mustBeErrorWithSubstring(t, err, "file[0].username/passsword in use and unsafe permissions "+ - "-rw-r--r-- on \"testdata/config.toml\"") + "-rw-r--r-- on \""+configPath+"\"") mustNotExist(t, statePath, groupPath, plainPath) mustBeOld(t, passwdPath)