mirror of
https://github.com/openfaas/faas.git
synced 2025-06-27 09:13:24 +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:
53
gateway/handlers/alerthandler_test.go
Normal file
53
gateway/handlers/alerthandler_test.go
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScale1to5(t *testing.T) {
|
||||
minReplicas := uint64(1)
|
||||
newReplicas := CalculateReplicas("firing", 1, DefaultMaxReplicas, minReplicas)
|
||||
if newReplicas != 5 {
|
||||
t.Log("Expected increment in blocks of 5 from 1 to 5")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestScale5to10(t *testing.T) {
|
||||
minReplicas := uint64(1)
|
||||
newReplicas := CalculateReplicas("firing", 5, DefaultMaxReplicas, minReplicas)
|
||||
if newReplicas != 10 {
|
||||
t.Log("Expected increment in blocks of 5 from 5 to 10")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestScaleCeilingOf20Replicas_Noaction(t *testing.T) {
|
||||
minReplicas := uint64(1)
|
||||
newReplicas := CalculateReplicas("firing", 20, DefaultMaxReplicas, minReplicas)
|
||||
if newReplicas != 20 {
|
||||
t.Log("Expected ceiling of 20 replicas")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestScaleCeilingOf20Replicas(t *testing.T) {
|
||||
minReplicas := uint64(1)
|
||||
newReplicas := CalculateReplicas("firing", 19, DefaultMaxReplicas, minReplicas)
|
||||
if newReplicas != 20 {
|
||||
t.Log("Expected ceiling of 20 replicas")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackingOff10to1(t *testing.T) {
|
||||
minReplicas := uint64(1)
|
||||
newReplicas := CalculateReplicas("resolved", 10, DefaultMaxReplicas, minReplicas)
|
||||
if newReplicas != 1 {
|
||||
t.Log("Expected backing off to 1 replica")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
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