@@ -6,11 +6,10 @@ package proxy
66import (
77 "context"
88 "net/http"
9+ "regexp"
910
1011 "testing"
1112
12- "regexp"
13-
1413 "github.com/openfaas/faas-cli/test"
1514)
1615
@@ -22,6 +21,7 @@ type deployProxyTest struct {
2221 replace bool
2322 update bool
2423 expectedOutput string
24+ expectedStatus int
2525}
2626
2727func runDeployProxyTest (t * testing.T , deployTest deployProxyTest ) {
@@ -34,32 +34,34 @@ func runDeployProxyTest(t *testing.T, deployTest deployProxyTest) {
3434 cliAuth := NewTestAuth (nil )
3535 proxyClient , _ := NewClient (cliAuth , s .URL , nil , & defaultCommandTimeout )
3636
37- stdout := test .CaptureStdout (func () {
38- proxyClient .DeployFunction (context .TODO (), & DeployFunctionSpec {
39- "fprocess" ,
40- "function" ,
41- "image" ,
42- "dXNlcjpwYXNzd29yZA==" ,
43- "language" ,
44- deployTest .replace ,
45- nil ,
46- "network" ,
47- []string {},
48- deployTest .update ,
49- []string {},
50- map [string ]string {},
51- map [string ]string {},
52- FunctionResourceRequest {},
53- false ,
54- tlsNoVerify ,
55- "" ,
56- "" ,
57- })
37+ statusCode , deployOutputStr := proxyClient .DeployFunction (context .TODO (), & DeployFunctionSpec {
38+ "fprocess" ,
39+ "function" ,
40+ "image" ,
41+ "dXNlcjpwYXNzd29yZA==" ,
42+ "language" ,
43+ deployTest .replace ,
44+ nil ,
45+ "network" ,
46+ []string {},
47+ deployTest .update ,
48+ []string {},
49+ map [string ]string {},
50+ map [string ]string {},
51+ FunctionResourceRequest {},
52+ false ,
53+ tlsNoVerify ,
54+ "" ,
55+ "" ,
5856 })
5957
58+ if statusCode != deployTest .expectedStatus {
59+ t .Fatalf ("Got: %d, expected: %d" , statusCode , deployTest .expectedStatus )
60+ }
61+
6062 r := regexp .MustCompile (deployTest .expectedOutput )
61- if ! r .MatchString (stdout ) {
62- t .Fatalf ("Output not matched: %s" , stdout )
63+ if ! r .MatchString (deployOutputStr ) {
64+ t .Fatalf ("Output not matched: %s" , deployOutputStr )
6365 }
6466}
6567
@@ -71,20 +73,23 @@ func Test_RunDeployProxyTests(t *testing.T) {
7173 replace : true ,
7274 update : false ,
7375 expectedOutput : `(?m:Deployed)` ,
76+ expectedStatus : http .StatusOK ,
7477 },
7578 {
7679 title : "404_Deploy" ,
7780 mockServerResponses : []int {http .StatusOK , http .StatusNotFound },
7881 replace : true ,
7982 update : false ,
8083 expectedOutput : `(?m:Unexpected status: 404)` ,
84+ expectedStatus : http .StatusNotFound ,
8185 },
8286 {
8387 title : "UpdateFailedDeployed" ,
8488 mockServerResponses : []int {http .StatusNotFound , http .StatusOK },
8589 replace : false ,
8690 update : true ,
8791 expectedOutput : `(?m:Deployed)` ,
92+ expectedStatus : http .StatusOK ,
8893 },
8994 }
9095 for _ , tst := range deployProxyTests {
0 commit comments