Skip to content

Commit

Permalink
test: refactor CORS tests and expand coverage
Browse files Browse the repository at this point in the history
- Add a new test function `TestDefaultConfig` to verify default configuration behavior in CORS tests

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Mar 10, 2024
1 parent 4447aeb commit 84d0919
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cors_test.go
Expand Up @@ -314,6 +314,17 @@ func TestValidateTauri(t *testing.T) {
assert.Nil(t, c.Validate())
}

func TestDefaultConfig(t *testing.T) {
config := DefaultConfig()
config.AllowAllOrigins = true
router := newTestRouter(config)
w := performRequest(router, "GET", "http://google.com")
assert.Equal(t, "get", w.Body.String())
assert.Equal(t, "*", w.Header().Get("Access-Control-Allow-Origin"))
assert.Empty(t, w.Header().Get("Access-Control-Allow-Credentials"))
assert.Empty(t, w.Header().Get("Access-Control-Expose-Headers"))
}

func TestPassesAllowOrigins(t *testing.T) {
router := newTestRouter(Config{
AllowOrigins: []string{"http://google.com"},
Expand Down

0 comments on commit 84d0919

Please sign in to comment.