Created
November 19, 2021 06:46
-
-
Save shrmpy/33635208047e79daf1adab393aff3689 to your computer and use it in GitHub Desktop.
refactor preflight request test for the addition of middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestPreflight(t *testing.T) { | |
// prep test data | |
conf := ebs.NewConfig() | |
expectMethods := "POST, GET, OPTIONS, PUT" | |
expectHeaders := "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization" | |
expectOrigin := "" | |
req := newTestRequest("OPTIONS") | |
// run the handler logic | |
result, err := ebs.MiddlewareCORS(conf, handler)(req) | |
assert.IsType(t, nil, err) | |
assert.Equal(t, http.StatusOK, result.StatusCode) | |
// check for expected CORS | |
assert.Equal(t, expectMethods, result.Headers["Access-Control-Allow-Methods"]) | |
assert.Equal(t, expectHeaders, result.Headers["Access-Control-Allow-Headers"]) | |
assert.Equal(t, expectOrigin, result.Headers["Access-Control-Allow-Origin"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment