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