opentofu/helper/structure/flatten_json_test.go
2017-03-28 12:59:46 +01:00

48 lines
1.2 KiB
Go

package structure
import (
"testing"
)
func TestFlattenJson_empty(t *testing.T) {
input := make(map[string]interface{}, 0)
expected := ""
actual, err := FlattenJsonToString(input)
if err != nil {
t.Fatalf("Expected not to throw an error while Flattening JSON, but got: %s", err)
}
if expected != actual {
t.Fatalf("Got: `%+v`. Expected: `%+v`", actual, expected)
}
}
func TestFlattenJson_singleItem(t *testing.T) {
input := make(map[string]interface{}, 1)
input["foo"] = "bar"
expected := `{"foo":"bar"}`
actual, err := FlattenJsonToString(input)
if err != nil {
t.Fatalf("Expected not to throw an error while Flattening JSON, but got: %s", err)
}
if expected != actual {
t.Fatalf("Got: `%+v`. Expected: `%+v`", actual, expected)
}
}
func TestFlattenJson_multipleItems(t *testing.T) {
input := make(map[string]interface{}, 1)
input["foo"] = "bar"
input["bar"] = "foo"
expected := `{"bar":"foo","foo":"bar"}`
actual, err := FlattenJsonToString(input)
if err != nil {
t.Fatalf("Expected not to throw an error while Flattening JSON, but got: %s", err)
}
if expected != actual {
t.Fatalf("Got: `%+v`. Expected: `%+v`", actual, expected)
}
}