Skip to content
Permalink
Browse files
added headers format
  • Loading branch information
jcabrerizo committed May 24, 2019
1 parent 15c2222 commit 0d988d4f3c06e21b35fc97aa94e8217c2c477cf4
Showing 2 changed files with 20 additions and 11 deletions.
@@ -57,7 +57,7 @@ func (cmd *Login) Metadata() command_metadata.CommandMetadata {
Flags: []cli.Flag{
cli.BoolFlag{Name: "skipSslChecks", Usage: "Skip SSL Checks"},
cli.BoolFlag{Name: "noCredentials", Usage: "No user/password needed"},
cli.StringSliceFlag{Name: "header, H", Usage: "Optional headers"},
cli.StringSliceFlag{Name: "header, H", Usage: "Optional headers. Format: 'hedaderName'='header value'"},
},
}
}
@@ -27,26 +27,35 @@ func TestConfig(t *testing.T) {

testFileFormat(t, "testconfig.json")
testFileFormat(t, "legacyConfig.json")
testCredentialsRequired(t, "testConfigHeaders.json")
testHeaders(t, "testConfigHeaders.json")

testCredentialsRequired(t, "testconfig.json",true)
testCredentialsRequired(t, "legacyConfig.json", false)
testCredentialsRequired(t, "testConfigHeaders.json", false)

testHeaders(t, "testconfig.json", nil)
testHeaders(t, "legacyConfig.json", nil)
testHeaders(t, "testConfigHeaders.json", mockHeaders())
}

func mockHeaders() (expectedHeaders map[string]interface{}) {
expectedHeaders=make(map[string]interface{})
expectedHeaders["Header1"]="Header one"
expectedHeaders["Header2"]="Header 2"
expectedHeaders["header3"]=""
return
}

func testCredentialsRequired(t *testing.T,testFile string) {
func testCredentialsRequired(t *testing.T,testFile string, expected bool) {
config :=getConfigFromFile(t,testFile)
isCredentialsRequired := config.GetCredentialsRequired()
assertBool(nil,t,"isCredentialsRequired",isCredentialsRequired,false)
assertBool(nil,t,"isCredentialsRequired",isCredentialsRequired,expected)
}

func testHeaders(t *testing.T, testFile string) {
func testHeaders(t *testing.T, testFile string, expectedHeaders map[string]interface{}) {
config :=getConfigFromFile(t,testFile)
userHeaders := config.GetUserHeaders()
expectedHeaders:=make(map[string]interface{})
expectedHeaders["Header1"]="Header one"
expectedHeaders["Header2"]="Header 2"
expectedHeaders["header3"]=""

assertHeaders(nil, t, userHeaders, expectedHeaders)

}

func assertHeaders(err error, t *testing.T, actualHeaders map[string]interface{}, expectedHeaders map[string]interface{}) {

0 comments on commit 0d988d4

Please sign in to comment.