github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/semantics_test.go (about) 1 package terraform 2 3 import ( 4 "testing" 5 ) 6 7 func TestSMCUserVariables(t *testing.T) { 8 c := testConfig(t, "smc-uservars") 9 10 // Required variables not set 11 errs := smcUserVariables(c, nil) 12 if len(errs) == 0 { 13 t.Fatal("should have errors") 14 } 15 16 // Required variables set, optional variables unset 17 errs = smcUserVariables(c, map[string]interface{}{"foo": "bar"}) 18 if len(errs) != 0 { 19 t.Fatalf("err: %#v", errs) 20 } 21 22 // Mapping element override 23 errs = smcUserVariables(c, map[string]interface{}{ 24 "foo": "bar", 25 "map.foo": "baz", 26 }) 27 if len(errs) == 0 { 28 t.Fatalf("err: %#v", errs) 29 } 30 31 // Mapping complete override 32 errs = smcUserVariables(c, map[string]interface{}{ 33 "foo": "bar", 34 "map": "baz", 35 }) 36 if len(errs) == 0 { 37 t.Fatal("should have errors") 38 } 39 40 } 41 42 func TestSMCUserVariables_mapFromJSON(t *testing.T) { 43 c := testConfig(t, "uservars-map") 44 45 // ensure that a single map in a list can satisfy a map variable, since it 46 // will be coerced later to a map 47 err := smcUserVariables(c, map[string]interface{}{ 48 "test_map": []map[string]interface{}{ 49 map[string]interface{}{ 50 "foo": "bar", 51 }, 52 }, 53 }) 54 if err != nil { 55 t.Fatal(err) 56 } 57 }