Skip to content

Commit 7825f01

Browse files
committed
Updated to include tests
1 parent d54c640 commit 7825f01

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/httpresponse/httpresponse_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,39 @@ func Test_httpresponse_004(t *testing.T) {
149149
assert.Equal("{\n \"code\": 404,\n \"reason\": \"not found\",\n \"detail\": \"this is the detail\"\n}\n", resp.Body.String())
150150
})
151151
}
152+
153+
func Test_httpresponse_005(t *testing.T) {
154+
assert := assert.New(t)
155+
156+
t.Run("Cors_0", func(t *testing.T) {
157+
resp := httptest.NewRecorder()
158+
assert.NoError(httpresponse.Cors(resp, "test"))
159+
assert.Equal(200, resp.Code)
160+
assert.Equal("test", resp.Header().Get("Access-Control-Allow-Origin"))
161+
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Methods"))
162+
})
163+
164+
t.Run("Cors_1", func(t *testing.T) {
165+
resp := httptest.NewRecorder()
166+
assert.NoError(httpresponse.Cors(resp, ""))
167+
assert.Equal(200, resp.Code)
168+
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
169+
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Methods"))
170+
})
171+
172+
t.Run("Cors_2", func(t *testing.T) {
173+
resp := httptest.NewRecorder()
174+
assert.NoError(httpresponse.Cors(resp, "", "get"))
175+
assert.Equal(200, resp.Code)
176+
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
177+
assert.Equal("GET", resp.Header().Get("Access-Control-Allow-Methods"))
178+
})
179+
180+
t.Run("Cors_3", func(t *testing.T) {
181+
resp := httptest.NewRecorder()
182+
assert.NoError(httpresponse.Cors(resp, "*", "get", "post"))
183+
assert.Equal(200, resp.Code)
184+
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
185+
assert.Equal("GET,POST", resp.Header().Get("Access-Control-Allow-Methods"))
186+
})
187+
}

0 commit comments

Comments
 (0)