Skip to content

Commit

Permalink
Updated to include tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djthorpe committed Jul 27, 2024
1 parent d54c640 commit 7825f01
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/httpresponse/httpresponse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,39 @@ func Test_httpresponse_004(t *testing.T) {
assert.Equal("{\n \"code\": 404,\n \"reason\": \"not found\",\n \"detail\": \"this is the detail\"\n}\n", resp.Body.String())
})
}

func Test_httpresponse_005(t *testing.T) {
assert := assert.New(t)

t.Run("Cors_0", func(t *testing.T) {
resp := httptest.NewRecorder()
assert.NoError(httpresponse.Cors(resp, "test"))
assert.Equal(200, resp.Code)
assert.Equal("test", resp.Header().Get("Access-Control-Allow-Origin"))
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Methods"))
})

t.Run("Cors_1", func(t *testing.T) {
resp := httptest.NewRecorder()
assert.NoError(httpresponse.Cors(resp, ""))
assert.Equal(200, resp.Code)
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Methods"))
})

t.Run("Cors_2", func(t *testing.T) {
resp := httptest.NewRecorder()
assert.NoError(httpresponse.Cors(resp, "", "get"))
assert.Equal(200, resp.Code)
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
assert.Equal("GET", resp.Header().Get("Access-Control-Allow-Methods"))
})

t.Run("Cors_3", func(t *testing.T) {
resp := httptest.NewRecorder()
assert.NoError(httpresponse.Cors(resp, "*", "get", "post"))
assert.Equal(200, resp.Code)
assert.Equal("*", resp.Header().Get("Access-Control-Allow-Origin"))
assert.Equal("GET,POST", resp.Header().Get("Access-Control-Allow-Methods"))
})
}

0 comments on commit 7825f01

Please sign in to comment.