mirror of
https://github.com/openfaas/faas.git
synced 2025-06-16 04:06:47 +00:00
Use types from requests
Signed-off-by: Alex Young <alex@heuris.io>
This commit is contained in:
parent
403236610a
commit
84ae82473c
@ -8,35 +8,26 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alexellis/faas/gateway/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PostFunctionRequest struct {
|
func createFunction(request requests.CreateFunctionRequest) (string, int, error) {
|
||||||
Image string `json:"image"`
|
|
||||||
EnvProcess string `json:"envProcess"`
|
|
||||||
Network string `json:"network"`
|
|
||||||
Service string `json:"service"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteFunctionRequest struct {
|
|
||||||
FunctionName string `json:"functionName"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func createFunction(request PostFunctionRequest) (string, int, error) {
|
|
||||||
marshalled, _ := json.Marshal(request)
|
marshalled, _ := json.Marshal(request)
|
||||||
return fireRequest("http://localhost:8080/system/functions", http.MethodPost, string(marshalled))
|
return fireRequest("http://localhost:8080/system/functions", http.MethodPost, string(marshalled))
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteFunction(name string) (string, int, error) {
|
func deleteFunction(name string) (string, int, error) {
|
||||||
marshalled, _ := json.Marshal(DeleteFunctionRequest{name})
|
marshalled, _ := json.Marshal(requests.DeleteFunctionRequest{name})
|
||||||
return fireRequest("http://localhost:8080/system/functions", http.MethodDelete, string(marshalled))
|
return fireRequest("http://localhost:8080/system/functions", http.MethodDelete, string(marshalled))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreate_ValidRequest(t *testing.T) {
|
func TestCreate_ValidRequest(t *testing.T) {
|
||||||
request := PostFunctionRequest{
|
request := requests.CreateFunctionRequest{
|
||||||
"functions/resizer",
|
Service: "test_resizer",
|
||||||
"",
|
Image: "functions/resizer",
|
||||||
"func_functions",
|
Network: "func_functions",
|
||||||
"test_resizer",
|
EnvProcess: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, code, err := createFunction(request)
|
_, code, err := createFunction(request)
|
||||||
@ -56,11 +47,11 @@ func TestCreate_ValidRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreate_InvalidImage(t *testing.T) {
|
func TestCreate_InvalidImage(t *testing.T) {
|
||||||
request := PostFunctionRequest{
|
request := requests.CreateFunctionRequest{
|
||||||
"a b c",
|
Service: "test_resizer",
|
||||||
"",
|
Image: "a b c",
|
||||||
"func_functions",
|
Network: "func_functions",
|
||||||
"test_resizer",
|
EnvProcess: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
body, code, err := createFunction(request)
|
body, code, err := createFunction(request)
|
||||||
@ -84,11 +75,11 @@ func TestCreate_InvalidImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreate_InvalidNetwork(t *testing.T) {
|
func TestCreate_InvalidNetwork(t *testing.T) {
|
||||||
request := PostFunctionRequest{
|
request := requests.CreateFunctionRequest{
|
||||||
"functions/resizer",
|
Service: "test_resizer",
|
||||||
"",
|
Image: "functions/resizer",
|
||||||
"non_existent_network",
|
Network: "non_existent_network",
|
||||||
"test_resizer",
|
EnvProcess: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
body, code, err := createFunction(request)
|
body, code, err := createFunction(request)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user