Skip to content

Commit

Permalink
Add header flag test
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Oct 13, 2023
1 parent 77f0b4e commit 9783af5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/eksctl-anywhere/cmd/aflag/header_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package aflag

import (
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestHeaderM(t *testing.T) {
tests := map[string]struct {
shouldErr bool
want http.Header
input string
}{
"success": {want: map[string][]string{"A": {"1", "2", "3"}, "B": {"2"}, "C": {"4"}}, input: `A=1;2;3,B=2,C=4`},
"bad input format 1": {shouldErr: true, input: `abc`, want: http.Header{}},
"bad input format 2": {shouldErr: true, input: `abc=123;abd=345,`, want: http.Header{}},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
h := http.Header{}
got := NewHeader(&h)
if err := got.Set(tc.input); err != nil {
if !tc.shouldErr {
t.Fatal(err)
}
}
if diff := cmp.Diff(tc.want, h); diff != "" {
t.Fatalf("diff: %s", diff)
}
})
}
}

0 comments on commit 9783af5

Please sign in to comment.