Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func TestAccessControlAllowOrigin(t *testing.T) {
// prepare data
conf := ebs.NewConfig()
conf.ExtensionId("HOSTNAME-TEST")
expectMethods := "POST, GET, OPTIONS, PUT"
expectHeaders := "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization"
expectOrigin := "https://HOSTNAME-TEST.ext-twitch.tv"
req := newTestRequest("GET")
// run 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