From 3b6d1cc9f8acf82be9f168657b6ecab1eb34721e Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Sun, 9 Jun 2019 15:35:58 -0400 Subject: removed redundant code --- svc/handlers_test.go | 48 +++++++++--------------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) (limited to 'svc/handlers_test.go') 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 { -- cgit 1.4.1-2-gfad0