]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - main_test.go
README.adoc: fix syntax for nested list
[nsscash/nsscash.git] / main_test.go
index 145abe91dfe5b8a0c53989e90133856feeeea528..ca03fc881dd294ac82c67400a66fe41b213236e2 100644 (file)
@@ -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)
                }
        }
@@ -218,6 +216,7 @@ func TestMainFetch(t *testing.T) {
                fetchCannotDeploy,
                fetchSecondFetchFails,
                fetchBasicAuth,
+               // TODO: fetchCannotDeployMultiple,
        }
 
        // HTTP tests
@@ -890,7 +889,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)
@@ -968,3 +967,52 @@ ca = "%[4]s"
        mustNotExist(t, statePath, plainPath, groupPath)
        mustBeOld(t, passwdPath)
 }
+
+/*
+TODO: implement code for this test
+
+func fetchCannotDeployMultiple(a args) {
+       t := a.t
+       newPlainDir := "testdata/x"
+       newPlainPath := newPlainDir + "/plain"
+       mustWriteConfig(t, fmt.Sprintf(`
+statepath = "%[1]s"
+
+[[file]]
+type = "group"
+url = "%[2]s/group"
+path = "%[3]s"
+
+[[file]]
+type = "plain"
+url = "%[2]s/plain"
+path = "%[4]s"
+`, statePath, a.url, groupPath, newPlainPath))
+       os.Mkdir(newPlainDir, 0755)
+       defer os.RemoveAll(newPlainDir)
+       mustCreate(t, groupPath)
+       mustCreate(t, newPlainPath)
+       mustHaveHash(t, groupPath, "da39a3ee5e6b4b0d3255bfef95601890afd80709")
+
+       *a.handler = func(w http.ResponseWriter, r *http.Request) {
+               if r.URL.Path == "/group" {
+                       fmt.Fprintln(w, "root:x:0:")
+               }
+               if r.URL.Path == "/plain" {
+                       fmt.Fprintln(w, "some file")
+               }
+       }
+
+       err := os.Chmod(newPlainDir, 0500)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       err = mainFetch(configPath)
+       mustBeErrorWithSubstring(t, err,
+               "permission denied")
+
+       mustNotExist(t, statePath, passwdPath, plainPath)
+       mustBeOld(t, groupPath, newPlainPath)
+}
+*/