summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-10 02:47:33 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-10 02:47:38 -0400
commit53b313e1deee01ccd46c41c12a111e15750b61af (patch)
tree152c40113582dfd69a67810395eead3d6613cef6 /svc
parente86aefb43ed494867fdb2122627d519fbbe397c7 (diff)
downloadgetwtxt-53b313e1deee01ccd46c41c12a111e15750b61af.tar.gz
closing test response bodies & readability improvements
Diffstat (limited to 'svc')
-rw-r--r--svc/handlers_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/svc/handlers_test.go b/svc/handlers_test.go
index 41a8851..c393957 100644
--- a/svc/handlers_test.go
+++ b/svc/handlers_test.go
@@ -18,11 +18,15 @@ import (
 
 func basicHandlerTest(path string, name string, t *testing.T) {
 	initTestConf()
+
 	t.Run(name, func(t *testing.T) {
 		w := httptest.NewRecorder()
 		req := httptest.NewRequest("GET", path, nil)
+
 		indexHandler(w, req)
 		resp := w.Result()
+		defer resp.Body.Close()
+
 		if resp.StatusCode != http.StatusOK {
 			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
 		}
@@ -41,9 +45,11 @@ func Test_indexHandler(t *testing.T) {
 }
 func Benchmark_indexHandler(b *testing.B) {
 	initTestConf()
+
 	w := httptest.NewRecorder()
 	req := httptest.NewRequest("GET", "http://localhost"+testport+"/", nil)
 	b.ResetTimer()
+
 	for i := 0; i < b.N; i++ {
 		indexHandler(w, req)
 	}
@@ -85,17 +91,24 @@ var endpointCases = []struct {
 func Test_apiEndpointHandler(t *testing.T) {
 	initTestConf()
 	mockRegistry()
+
 	for _, tt := range endpointCases {
+
 		t.Run(tt.name, func(t *testing.T) {
 			w := httptest.NewRecorder()
 			apiEndpointHandler(w, tt.req)
+
 			resp := w.Result()
+			defer resp.Body.Close()
+
 			if resp.StatusCode != tt.status {
 				t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
 			}
+
 			if tt.status == http.StatusOK {
 				var body []byte
 				buf := bytes.NewBuffer(body)
+
 				err := resp.Write(buf)
 				if err != nil {
 					t.Errorf("%v\n", err)
@@ -113,8 +126,10 @@ func Test_apiEndpointHandler(t *testing.T) {
 func Benchmark_apiEndpointHandler(b *testing.B) {
 	initTestConf()
 	mockRegistry()
+
 	w := httptest.NewRecorder()
 	b.ResetTimer()
+
 	for _, tt := range endpointCases {
 		for i := 0; i < b.N; i++ {
 			apiEndpointHandler(w, tt.req)
@@ -125,14 +140,19 @@ func Benchmark_apiEndpointHandler(b *testing.B) {
 func Test_apiTagsBaseHandler(t *testing.T) {
 	initTestConf()
 	mockRegistry()
+
 	t.Run("apiTagsBaseHandler", func(t *testing.T) {
 		w := httptest.NewRecorder()
 		req := httptest.NewRequest("GET", "http://localhost"+testport+"/api/plain/tags", nil)
+
 		apiTagsBaseHandler(w, req)
 		resp := w.Result()
+		defer resp.Body.Close()
+
 		if resp.StatusCode != http.StatusOK {
 			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
 		}
+
 		bd, err := ioutil.ReadAll(resp.Body)
 		if err != nil {
 			t.Errorf("%v\n", err)
@@ -148,6 +168,7 @@ func Benchmark_apiTagsBaseHandler(b *testing.B) {
 	w := httptest.NewRecorder()
 	r := httptest.NewRequest("GET", "http://localhost"+testport+"/api/plain/tags", nil)
 	b.ResetTimer()
+
 	for i := 0; i < b.N; i++ {
 		apiTagsBaseHandler(w, r)
 	}
@@ -155,15 +176,20 @@ func Benchmark_apiTagsBaseHandler(b *testing.B) {
 func Test_apiTagsHandler(t *testing.T) {
 	initTestConf()
 	mockRegistry()
+
 	t.Run("apiTagsHandler", func(t *testing.T) {
 		w := httptest.NewRecorder()
 		req := httptest.NewRequest("GET", "http://localhost"+testport+"/api/plain/tags/programming", nil)
+
 		apiTagsHandler(w, req)
 		resp := w.Result()
+		defer resp.Body.Close()
+
 		data, err := ioutil.ReadAll(resp.Body)
 		if err != nil {
 			t.Errorf("%v\n", err)
 		}
+
 		if resp.StatusCode != http.StatusOK {
 			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
 		}
@@ -179,6 +205,7 @@ func Benchmark_apiTagsHandler(b *testing.B) {
 	w := httptest.NewRecorder()
 	r := httptest.NewRequest("GET", "http://localhost"+testport+"/api/plain/tags/programming", nil)
 	b.ResetTimer()
+
 	for i := 0; i < b.N; i++ {
 		apiTagsHandler(w, r)
 	}
@@ -198,8 +225,12 @@ func Test_cssHandler(t *testing.T) {
 
 	t.Run(name, func(t *testing.T) {
 		cssHandler(w, req)
+
 		resp := w.Result()
+		defer resp.Body.Close()
+
 		body, _ := ioutil.ReadAll(resp.Body)
+
 		if resp.StatusCode != 200 {
 			t.Errorf("cssHandler(): %v\n", resp.StatusCode)
 		}
1549'>^
7dc8fef8 ^
36e4e71e ^

4a383291 ^
78a7d762 ^
e952d6cb ^
78a7d762 ^
e952d6cb ^
4ea0f69a ^

7838675f ^

07069888 ^

07069888 ^
7838675f ^

1891697f ^
755e7df1 ^
a3d5f44b ^
66a8d4ff ^
7838675f ^
7dc8fef8 ^
f435be33 ^
500cf259 ^


7dc8fef8 ^



240394a4 ^



240394a4 ^
7dc8fef8 ^
240394a4 ^




7dc8fef8 ^
240394a4 ^



e5fb3d74 ^
240394a4 ^

240394a4 ^
7dc8fef8 ^



7b33b517 ^

176e8a68 ^
7b33b517 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98