diff --git a/helper/structure/structure_test.go b/helper/structure/structure_test.go index 7eb8dc27b..9350c95c2 100644 --- a/helper/structure/structure_test.go +++ b/helper/structure/structure_test.go @@ -4,10 +4,7 @@ import ( "testing" ) -func TestNormalizeJsonString(t *testing.T) { - var err error - var actual string - +func TestNormalizeJsonString_valid(t *testing.T) { // Well formatted and valid. validJson := `{ "abc": { @@ -24,7 +21,7 @@ func TestNormalizeJsonString(t *testing.T) { }` expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}` - actual, err = NormalizeJsonString(validJson) + actual, err := NormalizeJsonString(validJson) if err != nil { t.Fatalf("Expected not to throw an error while parsing JSON, but got: %s", err) } @@ -32,7 +29,9 @@ func TestNormalizeJsonString(t *testing.T) { if actual != expected { t.Fatalf("Got:\n\n%s\n\nExpected:\n\n%s\n", actual, expected) } +} +func TestNormalizeJsonString_invalid(t *testing.T) { // Well formatted but not valid, // missing closing squre bracket. invalidJson := `{ @@ -45,7 +44,8 @@ func TestNormalizeJsonString(t *testing.T) { } } }` - actual, err = NormalizeJsonString(invalidJson) + expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}` + actual, err := NormalizeJsonString(invalidJson) if err == nil { t.Fatalf("Expected to throw an error while parsing JSON, but got: %s", err) }