github.com/mvisonneau/terraform@v0.11.12-beta1/helper/structure/expand_json_test.go (about) 1 package structure 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestExpandJson_emptyString(t *testing.T) { 9 _, err := ExpandJsonFromString("") 10 if err == nil { 11 t.Fatal("Expected to throw an error while Expanding JSON") 12 } 13 } 14 15 func TestExpandJson_singleItem(t *testing.T) { 16 input := `{ 17 "foo": "bar" 18 }` 19 expected := make(map[string]interface{}, 1) 20 expected["foo"] = "bar" 21 actual, err := ExpandJsonFromString(input) 22 if err != nil { 23 t.Fatalf("Expected not to throw an error while Expanding JSON, but got: %s", err) 24 } 25 26 if !reflect.DeepEqual(actual, expected) { 27 t.Fatalf("Got:\n\n%+v\n\nExpected:\n\n%+v\n", actual, expected) 28 } 29 } 30 31 func TestExpandJson_multipleItems(t *testing.T) { 32 input := `{ 33 "foo": "bar", 34 "hello": "world" 35 }` 36 expected := make(map[string]interface{}, 1) 37 expected["foo"] = "bar" 38 expected["hello"] = "world" 39 40 actual, err := ExpandJsonFromString(input) 41 if err != nil { 42 t.Fatalf("Expected not to throw an error while Expanding JSON, but got: %s", err) 43 } 44 45 if !reflect.DeepEqual(actual, expected) { 46 t.Fatalf("Got:\n\n%+v\n\nExpected:\n\n%+v\n", actual, expected) 47 } 48 }