github.com/HashDataInc/packer@v1.3.2/helper/flag-kv/flag_test.go (about) 1 package kvflag 2 3 import ( 4 "flag" 5 "reflect" 6 "testing" 7 ) 8 9 func TestFlag_impl(t *testing.T) { 10 var _ flag.Value = new(Flag) 11 } 12 13 func TestFlag(t *testing.T) { 14 cases := []struct { 15 Input string 16 Output map[string]string 17 Error bool 18 }{ 19 { 20 "key=value", 21 map[string]string{"key": "value"}, 22 false, 23 }, 24 25 { 26 "key=", 27 map[string]string{"key": ""}, 28 false, 29 }, 30 31 { 32 "key=foo=bar", 33 map[string]string{"key": "foo=bar"}, 34 false, 35 }, 36 37 { 38 "key", 39 nil, 40 true, 41 }, 42 } 43 44 for _, tc := range cases { 45 f := new(Flag) 46 err := f.Set(tc.Input) 47 if (err != nil) != tc.Error { 48 t.Fatalf("bad error. Input: %#v", tc.Input) 49 } 50 51 actual := map[string]string(*f) 52 if !reflect.DeepEqual(actual, tc.Output) { 53 t.Fatalf("bad: %#v", actual) 54 } 55 } 56 }