mirror of
https://github.com/openfaas/faas.git
synced 2025-06-20 04:56:38 +00:00
Moved unit test files inside same directory as test target
The unit tests were inside the `gateway/tests` directory which had no effect to the coverage for `go test`. Therefore, moved the tests inside the same directory as the test target. Signed-off-by: Ken Fukuyama <kenfdev@gmail.com>
This commit is contained in:
34
gateway/handlers/cors_test.go
Normal file
34
gateway/handlers/cors_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user