X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=main_test.go;h=4e9a83bcb8842620627c122743a48bd682377f6b;hb=271a54506b9931ca647f065d3b686b1932b3600b;hp=31c9e50064f21276776f5e344edc62da53f9aad0;hpb=a8a8f9daebe164d067d004458679dd7e7f0dc087;p=nsscash%2Fnsscash.git diff --git a/main_test.go b/main_test.go index 31c9e50..4e9a83b 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) @@ -198,6 +198,7 @@ func TestMainFetch(t *testing.T) { // Perform most tests with passwd for simplicity fetchPasswdCacheFileDoesNotExist, fetchPasswd404, + fetchPasswdUnexpected304, fetchPasswdEmpty, fetchPasswdInvalid, fetchPasswdLimits, @@ -329,6 +330,24 @@ func fetchPasswd404(a args) { mustBeOld(a.t, passwdPath) } +func fetchPasswdUnexpected304(a args) { + t := a.t + mustWritePasswdConfig(t, a.url) + mustCreate(t, passwdPath) + + *a.handler = func(w http.ResponseWriter, r *http.Request) { + // 304 + w.WriteHeader(http.StatusNotModified) + } + + err := mainFetch(configPath) + mustBeErrorWithSubstring(t, err, + "status code 304 but did not send If-Modified-Since") + + mustNotExist(t, statePath, plainPath, groupPath) + mustBeOld(a.t, passwdPath) +} + func fetchPasswdEmpty(a args) { t := a.t mustWritePasswdConfig(t, a.url)