From 84ae82473cb22132ce3ac73b21631ba49120c2bb Mon Sep 17 00:00:00 2001 From: Alex Young <alex@heuris.io> Date: Wed, 20 Sep 2017 20:29:43 +0100 Subject: [PATCH] Use types from requests Signed-off-by: Alex Young <alex@heuris.io> --- .../tests/integration/createfunction_test.go | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/gateway/tests/integration/createfunction_test.go b/gateway/tests/integration/createfunction_test.go index b18db406..3f62d0d2 100644 --- a/gateway/tests/integration/createfunction_test.go +++ b/gateway/tests/integration/createfunction_test.go @@ -8,35 +8,26 @@ import ( "net/http" "strings" "testing" -) - -type PostFunctionRequest struct { - Image string `json:"image"` - EnvProcess string `json:"envProcess"` - Network string `json:"network"` - Service string `json:"service"` -} -type DeleteFunctionRequest struct { - FunctionName string `json:"functionName"` -} + "github.com/alexellis/faas/gateway/requests" +) -func createFunction(request PostFunctionRequest) (string, int, error) { +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(DeleteFunctionRequest{name}) + marshalled, _ := json.Marshal(requests.DeleteFunctionRequest{name}) return fireRequest("http://localhost:8080/system/functions", http.MethodDelete, string(marshalled)) } func TestCreate_ValidRequest(t *testing.T) { - request := PostFunctionRequest{ - "functions/resizer", - "", - "func_functions", - "test_resizer", + request := requests.CreateFunctionRequest{ + Service: "test_resizer", + Image: "functions/resizer", + Network: "func_functions", + EnvProcess: "", } _, code, err := createFunction(request) @@ -56,11 +47,11 @@ func TestCreate_ValidRequest(t *testing.T) { } func TestCreate_InvalidImage(t *testing.T) { - request := PostFunctionRequest{ - "a b c", - "", - "func_functions", - "test_resizer", + request := requests.CreateFunctionRequest{ + Service: "test_resizer", + Image: "a b c", + Network: "func_functions", + EnvProcess: "", } body, code, err := createFunction(request) @@ -84,11 +75,11 @@ func TestCreate_InvalidImage(t *testing.T) { } func TestCreate_InvalidNetwork(t *testing.T) { - request := PostFunctionRequest{ - "functions/resizer", - "", - "non_existent_network", - "test_resizer", + request := requests.CreateFunctionRequest{ + Service: "test_resizer", + Image: "functions/resizer", + Network: "non_existent_network", + EnvProcess: "", } body, code, err := createFunction(request) -- GitLab