]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - main_test.go
nsscash: main_test: refactor in preparation for HTTPS
[nsscash/nsscash.git] / main_test.go
index 7ccaca93dbff536cccc2968a8494aa3350486bcb..ab5e9b7111399a5d999d1b794712d8e05a31e4c0 100644 (file)
@@ -207,6 +207,12 @@ func TestMainFetch(t *testing.T) {
                fetchSecondFetchFails,
        }
 
+       for _, f := range tests {
+               runMainTest(t, f)
+       }
+}
+
+func runMainTest(t *testing.T, f func(args)) {
        cleanup := []string{
                configPath,
                statePath,
@@ -215,7 +221,6 @@ func TestMainFetch(t *testing.T) {
                groupPath,
        }
 
-       for _, f := range tests {
                // NOTE: This is not guaranteed to work according to reflect's
                // documentation but seems to work reliable for normal
                // functions.
@@ -236,9 +241,10 @@ func TestMainFetch(t *testing.T) {
                        }
 
                        var handler func(http.ResponseWriter, *http.Request)
-                       ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-                               handler(w, r)
-                       }))
+                       ts := httptest.NewServer(http.HandlerFunc(
+                               func(w http.ResponseWriter, r *http.Request) {
+                                       handler(w, r)
+                               }))
                        defer ts.Close()
 
                        f(args{
@@ -247,7 +253,6 @@ func TestMainFetch(t *testing.T) {
                                handler: &handler,
                        })
                })
-       }
 }
 
 func fetchPasswdCacheFileDoesNotExist(a args) {
@@ -728,7 +733,7 @@ path = "%[4]s"
                "status code 404")
 
        mustNotExist(t, statePath, plainPath)
-       // Even tough passwd was successfully fetched, no files were modified
+       // Even though passwd was successfully fetched, no files were modified
        // because the second fetch failed
        mustBeOld(t, passwdPath, groupPath)
 }