forked from artyom/update-cloudformation-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
29 lines (27 loc) · 861 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import "testing"
func Test_parseKvs(t *testing.T) {
for _, tc := range []struct {
input []string
pairsParsed int
wantErr bool
}{
{input: nil},
{input: []string{"\n"}},
{input: []string{"k=v"}, pairsParsed: 1},
{input: []string{"k=v", "k=v"}, wantErr: true},
{input: []string{"k=v", "k2=v"}, pairsParsed: 2},
{input: []string{"k=v", "", "k2=v", ""}, pairsParsed: 2},
{input: []string{"k=v", "k2=v", "k=v"}, wantErr: true},
{input: []string{"k=v", "junk"}, wantErr: true},
{input: []string{"k= ", "k2=v"}, wantErr: true},
} {
got, err := parseKvs(tc.input)
if tc.wantErr != (err != nil) {
t.Errorf("input: %q, want error: %v, got error: %v", tc.input, tc.wantErr, err)
}
if l := len(got); l != tc.pairsParsed {
t.Errorf("input: %q, got %d kv pairs, want %d", tc.input, l, tc.pairsParsed)
}
}
}