mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 08:46:48 +00:00
Reinstating tests
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
parent
2229e922d7
commit
ca9a7fe97c
@ -4,21 +4,101 @@
|
||||
package inttests
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/alexellis/faas/gateway/requests"
|
||||
)
|
||||
|
||||
func TestCreate_ValidJson_InvalidFunction(t *testing.T) {
|
||||
reqBody := `{}`
|
||||
_, code, err := fireRequest("http://localhost:8080/system/functions", http.MethodPost, reqBody)
|
||||
func createFunction(request requests.CreateFunctionRequest) (string, int, error) {
|
||||
marshalled, _ := json.Marshal(request)
|
||||
return fireRequest("http://localhost:8080/system/functions", http.MethodPost, string(marshalled))
|
||||
}
|
||||
|
||||
func deleteFunction(name string) (string, int, error) {
|
||||
marshalled, _ := json.Marshal(requests.DeleteFunctionRequest{name})
|
||||
return fireRequest("http://localhost:8080/system/functions", http.MethodDelete, string(marshalled))
|
||||
}
|
||||
|
||||
func TestCreate_ValidRequest(t *testing.T) {
|
||||
request := requests.CreateFunctionRequest{
|
||||
Service: "test_resizer",
|
||||
Image: "functions/resizer",
|
||||
Network: "func_functions",
|
||||
EnvProcess: "",
|
||||
}
|
||||
|
||||
_, code, err := createFunction(request)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if code != http.StatusBadRequest {
|
||||
t.Errorf("Got HTTP code: %d, want %d\n", code, http.StatusBadRequest)
|
||||
expectedErrorCode := http.StatusOK
|
||||
if code != expectedErrorCode {
|
||||
t.Errorf("Got HTTP code: %d, want %d\n", code, expectedErrorCode)
|
||||
return
|
||||
}
|
||||
|
||||
deleteFunction("test_resizer")
|
||||
}
|
||||
|
||||
func TestCreate_InvalidImage(t *testing.T) {
|
||||
request := requests.CreateFunctionRequest{
|
||||
Service: "test_resizer",
|
||||
Image: "a b c",
|
||||
Network: "func_functions",
|
||||
EnvProcess: "",
|
||||
}
|
||||
|
||||
body, code, err := createFunction(request)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
expectedErrorCode := http.StatusBadRequest
|
||||
if code != expectedErrorCode {
|
||||
t.Errorf("Got HTTP code: %d, want %d\n", code, expectedErrorCode)
|
||||
return
|
||||
}
|
||||
|
||||
expectedErrorSlice := "is not a valid repository/tag"
|
||||
if !strings.Contains(body, expectedErrorSlice) {
|
||||
t.Errorf("Error message %s does not contain: %s\n", body, expectedErrorSlice)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreate_InvalidNetwork(t *testing.T) {
|
||||
request := requests.CreateFunctionRequest{
|
||||
Service: "test_resizer",
|
||||
Image: "functions/resizer",
|
||||
Network: "non_existent_network",
|
||||
EnvProcess: "",
|
||||
}
|
||||
|
||||
body, code, err := createFunction(request)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
expectedErrorCode := http.StatusBadRequest
|
||||
if code != expectedErrorCode {
|
||||
t.Errorf("Got HTTP code: %d, want %d\n", code, expectedErrorCode)
|
||||
return
|
||||
}
|
||||
|
||||
expectedErrorSlice := "network non_existent_network not found"
|
||||
if !strings.Contains(body, expectedErrorSlice) {
|
||||
t.Errorf("Error message %s does not contain: %s\n", body, expectedErrorSlice)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user