github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/flag_kv_test.go (about) 1 package command 2 3 import ( 4 "flag" 5 "reflect" 6 "testing" 7 ) 8 9 func TestFlagStringKV_impl(t *testing.T) { 10 var _ flag.Value = new(FlagStringKV) 11 } 12 13 func TestFlagStringKV(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 "map.key=foo", 39 map[string]string{"map.key": "foo"}, 40 false, 41 }, 42 43 { 44 "key", 45 nil, 46 true, 47 }, 48 49 { 50 "key=/path", 51 map[string]string{"key": "/path"}, 52 false, 53 }, 54 } 55 56 for _, tc := range cases { 57 f := new(FlagStringKV) 58 err := f.Set(tc.Input) 59 if err != nil != tc.Error { 60 t.Fatalf("bad error. Input: %#v\n\nError: %s", tc.Input, err) 61 } 62 63 actual := map[string]string(*f) 64 if !reflect.DeepEqual(actual, tc.Output) { 65 t.Fatalf("bad: %#v", actual) 66 } 67 } 68 }