github.com/jpedro/terraform@v0.11.12-beta1/helper/variables/parse_test.go (about) 1 package variables 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 ) 8 9 func TestParseInput(t *testing.T) { 10 cases := []struct { 11 Name string 12 Input string 13 Result interface{} 14 Error bool 15 }{ 16 { 17 "unquoted string", 18 "foo", 19 "foo", 20 false, 21 }, 22 23 { 24 "number", 25 "1", 26 "1", 27 false, 28 }, 29 30 { 31 "float", 32 "1.2", 33 "1.2", 34 false, 35 }, 36 37 { 38 "hex number", 39 "0x12", 40 "0x12", 41 false, 42 }, 43 44 { 45 "bool", 46 "true", 47 "true", 48 false, 49 }, 50 51 { 52 "list", 53 `["foo"]`, 54 []interface{}{"foo"}, 55 false, 56 }, 57 58 { 59 "map", 60 `{ foo = "bar" }`, 61 map[string]interface{}{"foo": "bar"}, 62 false, 63 }, 64 } 65 66 for i, tc := range cases { 67 t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) { 68 actual, err := ParseInput(tc.Input) 69 if (err != nil) != tc.Error { 70 t.Fatalf("err: %s", err) 71 } 72 if err != nil { 73 return 74 } 75 76 if !reflect.DeepEqual(actual, tc.Result) { 77 t.Fatalf("bad: %#v", actual) 78 } 79 }) 80 } 81 }