summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-09 15:35:58 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-09 15:35:58 -0400
commit3b6d1cc9f8acf82be9f168657b6ecab1eb34721e (patch)
treefa2fab9c0354976935d7668b658fbc546acfdbcd /svc
parente75c7fd91d3677afb5d76bf8bc5e56b8ee5b365a (diff)
downloadgetwtxt-3b6d1cc9f8acf82be9f168657b6ecab1eb34721e.tar.gz
removed redundant code
Diffstat (limited to 'svc')
-rw-r--r--svc/handlers_test.go48
1 files changed, 9 insertions, 39 deletions
diff --git a/svc/handlers_test.go b/svc/handlers_test.go
index 97a5d59..82a8d86 100644
--- a/svc/handlers_test.go
+++ b/svc/handlers_test.go
@@ -15,11 +15,12 @@ import (
 //    /api
 //    /api/plain
 // later, then I'll change the tests.
-func Test_indexHandler(t *testing.T) {
+
+func basicHandlerTest(path string, name string, t *testing.T) {
 	initTestConf()
-	t.Run("indexHandler", func(t *testing.T) {
+	t.Run(name, func(t *testing.T) {
 		w := httptest.NewRecorder()
-		req := httptest.NewRequest("GET", "http://localhost"+testport+"/", nil)
+		req := httptest.NewRequest("GET", path, nil)
 		indexHandler(w, req)
 		resp := w.Result()
 		if resp.StatusCode != http.StatusOK {
@@ -35,6 +36,9 @@ func Test_indexHandler(t *testing.T) {
 		}
 	})
 }
+func Test_indexHandler(t *testing.T) {
+	basicHandlerTest("http://localhost"+testport+"/", "indexHandler", t)
+}
 func Benchmark_indexHandler(b *testing.B) {
 	initTestConf()
 	w := httptest.NewRecorder()
@@ -45,44 +49,10 @@ func Benchmark_indexHandler(b *testing.B) {
 	}
 }
 func Test_apiBaseHandler(t *testing.T) {
-	initTestConf()
-	t.Run("indexHandler", func(t *testing.T) {
-		w := httptest.NewRecorder()
-		req := httptest.NewRequest("GET", "http://localhost"+testport+"/api", nil)
-		indexHandler(w, req)
-		resp := w.Result()
-		if resp.StatusCode != http.StatusOK {
-			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
-		}
-
-		bt, err := ioutil.ReadAll(resp.Body)
-		if err != nil {
-			t.Errorf("%v\n", err)
-		}
-		if !reflect.DeepEqual(bt, staticCache.index) {
-			t.Errorf("Byte mismatch\n")
-		}
-	})
+	basicHandlerTest("http://localhost"+testport+"/api", "apiBaseHandler", t)
 }
 func Test_apiFormatHandler(t *testing.T) {
-	initTestConf()
-	t.Run("indexHandler", func(t *testing.T) {
-		w := httptest.NewRecorder()
-		req := httptest.NewRequest("GET", "http://localhost"+testport+"/api/plain", nil)
-		indexHandler(w, req)
-		resp := w.Result()
-		if resp.StatusCode != http.StatusOK {
-			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
-		}
-
-		bt, err := ioutil.ReadAll(resp.Body)
-		if err != nil {
-			t.Errorf("%v\n", err)
-		}
-		if !reflect.DeepEqual(bt, staticCache.index) {
-			t.Errorf("Byte mismatch\n")
-		}
-	})
+	basicHandlerTest("http://localhost"+testport+"/api/format", "apiFormatHandler", t)
 }
 
 var endpointCases = []struct {