faas/gateway/handlers/cors_test.go
Alex Ellis (VMware) af0ccc9a45 Add Copyright headers where missing in handlers
- Added Copyright in handlers where missing
- Renamed Project to Author(s) where needed

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-09-03 13:26:58 +01:00

38 lines
969 B
Go

// Copyright (c) OpenFaaS Author(s). All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package handlers
import (
"net/http"
"net/http/httptest"
"testing"
)
type customHandler struct {
}
func (h customHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func Test_HeadersAdded(t *testing.T) {
rr := httptest.NewRecorder()
handler := customHandler{}
host := "store.openfaas.com"
decorated := DecorateWithCORS(handler, host)
request, _ := http.NewRequest(http.MethodGet, "/", nil)
decorated.ServeHTTP(rr, request)
actual := rr.Header().Get("Access-Control-Allow-Origin")
if actual != host {
t.Errorf("Access-Control-Allow-Origin: want: %s got: %s", host, actual)
}
actualMethods := rr.Header().Get("Access-Control-Allow-Methods")
if actualMethods != http.MethodGet {
t.Errorf("Access-Control-Allow-Methods: want: %s got: %s", http.MethodGet, actualMethods)
}
}