Skip to content

Commit

Permalink
Change header syntax to equal sign
Browse files Browse the repository at this point in the history
To align with other key-value CLIs where the equal is more
typical than colon.
  • Loading branch information
ccremer committed May 17, 2020
1 parent c997d16 commit 2758b3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func ParseConfig(version, commit, date string, fs *flag.FlagSet, args []string)

func ConvertHeaders(headers []string, header *http.Header) {
for _, hd := range headers {
arr := strings.SplitN(hd, ":", 2)
arr := strings.SplitN(hd, "=", 2)
if len(arr) < 2 {
log.WithFields(log.Fields{
"arg": hd,
"error": "cannot split: missing colon",
"error": "cannot split: missing equal sign",
}).Warn("Could not parse header, ignoring")
continue
}
Expand Down
16 changes: 8 additions & 8 deletions cfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestConvertHeaders(t *testing.T) {
{
name: "WhenValidEntry_ThenParse",
args: args{
headers: []string{"Authentication: Bearer <token>"},
headers: []string{"Authentication= Bearer <token>"},
header: &http.Header{},
},
verify: func(header *http.Header) {
Expand All @@ -52,7 +52,7 @@ func TestConvertHeaders(t *testing.T) {
{
name: "GivenValidEntry_WhenSpacesAroundValues_ThenTrim",
args: args{
headers: []string{" Authentication: Bearer <token> "},
headers: []string{" Authentication = Bearer <token> "},
header: &http.Header{},
},
verify: func(header *http.Header) {
Expand Down Expand Up @@ -123,20 +123,20 @@ func TestParseConfig(t *testing.T) {
},
{
name: "GivenHeaderFlags_WhenMultipleHeadersSpecified_ThenFillArray",
args: []string{"--symo.header", "key1:value1", "--symo.header", "KEY2: value2"},
args: []string{"--symo.header", "key1=value1", "--symo.header", "KEY2= value2"},
verify: func(c *Configuration) {
assert.Contains(t, c.Symo.Headers, "key1:value1")
assert.Contains(t, c.Symo.Headers, "KEY2: value2")
assert.Contains(t, c.Symo.Headers, "key1=value1")
assert.Contains(t, c.Symo.Headers, "KEY2= value2")
},
},
{
name: "GivenHeaderEnvVar_WhenMultipleHeadersSpecified_ThenFillArray",
envs: map[string]string{
"SYMO_HEADER": "key1:value1, KEY2: value2",
"SYMO_HEADER": "key1=value1, KEY2= value2",
},
verify: func(c *Configuration) {
assert.Contains(t, c.Symo.Headers, "key1:value1")
assert.Contains(t, c.Symo.Headers, " KEY2: value2")
assert.Contains(t, c.Symo.Headers, "key1=value1")
assert.Contains(t, c.Symo.Headers, " KEY2= value2")
},
},
{
Expand Down

0 comments on commit 2758b3b

Please sign in to comment.