mirror of
https://github.com/openfaas/faas.git
synced 2025-06-24 07:43:25 +00:00
Refactoring: variable names, adding tests and http constants
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
36
gateway/tests/cors_test.go
Normal file
36
gateway/tests/cors_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/openfaas/faas/gateway/handlers"
|
||||
)
|
||||
|
||||
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 := handlers.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 != "GET" {
|
||||
t.Errorf("Access-Control-Allow-Methods: want: %s got: %s", "GET", actualMethods)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user