Skip to content

Commit

Permalink
gatewayOverrideTests
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis <[email protected]>
  • Loading branch information
alexellis committed Oct 16, 2017
1 parent fe0b893 commit 246f5bc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
19 changes: 15 additions & 4 deletions commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ func runDeploy(cmd *cobra.Command, args []string) {
return
}

// Override gateway if passed
if len(gateway) > 0 && gateway != parsedServices.Provider.GatewayURL {
parsedServices.Provider.GatewayURL = gateway
}
parsedServices.Provider.GatewayURL = getGatewayURL(gateway, defaultGateway, parsedServices.Provider.GatewayURL)

// Override network if passed
if len(network) > 0 && network != defaultNetwork {
Expand Down Expand Up @@ -214,3 +211,17 @@ func mergeMap(i map[string]string, j map[string]string) map[string]string {
}
return merged
}

func getGatewayURL(argumentURL string, defaultURL string, yamlURL string) string {
var gatewayURL string

if len(argumentURL) > 0 && argumentURL != defaultURL {
gatewayURL = argumentURL
} else if len(yamlURL) > 0 {
gatewayURL = yamlURL
} else {
gatewayURL = defaultURL
}

return gatewayURL
}
59 changes: 59 additions & 0 deletions commands/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,65 @@ import (
"github.com/openfaas/faas-cli/test"
)

func Test_getGatewayURL(t *testing.T) {
defaultValue := "http://localhost:8080"
testCases := []struct {
name string
defaultURL string
yamlURL string
argumentURL string
expectedURL string
}{
{
name: "Nothing provided",
defaultURL: defaultValue,
yamlURL: "",
argumentURL: "",
expectedURL: "http://localhost:8080",
},
{
name: "Only YAML provided",
defaultURL: defaultValue,
yamlURL: "http://remote1:8080",
argumentURL: "",
expectedURL: "http://remote1:8080",
},
{
name: "Only argument override",
defaultURL: defaultValue,
yamlURL: "",
argumentURL: "http://remote2:8080",
expectedURL: "http://remote2:8080",
},
{
name: "Prioritize argument over YAML when argument is not default",
defaultURL: defaultValue,
yamlURL: "http://remote-yml:8080",
argumentURL: "http://remote-arg:8080",
expectedURL: "http://remote-arg:8080",
},
{
name: "When argument is default use YAML",
defaultURL: defaultValue,
yamlURL: "http://remote-yml:8080",
argumentURL: defaultValue,
expectedURL: "http://remote-yml:8080",
},
}

fails := 0
for _, testCase := range testCases {
url := getGatewayURL(testCase.argumentURL, testCase.defaultURL, testCase.yamlURL)
if url != testCase.expectedURL {
t.Logf("gatewayURL %s\nwant: %s, got: %s", testCase.name, testCase.expectedURL, url)
fails++
}
}
if fails > 0 {
t.Fail()
}
}

func Test_deploy(t *testing.T) {
s := test.MockHttpServer(t, []test.Request{
{
Expand Down

0 comments on commit 246f5bc

Please sign in to comment.