diff --git a/pkg/model/model_test.go b/pkg/model/model_test.go index aa1b3b61f4..9e58205884 100644 --- a/pkg/model/model_test.go +++ b/pkg/model/model_test.go @@ -28,11 +28,48 @@ func TestInfoJsonMarshal(t *testing.T) { }, } + type infoJSON struct { + Name string `json:"name"` + Author []string `json:"author"` + Tags []string `json:"tags"` + Description string `json:"description"` + Reference string `json:"reference"` + Severity string `json:"severity"` + Metadata struct { + StringKey string `json:"string_key"` + ArrayKey []string `json:"array_key"` + MapKey interface{} `json:"map_key"` + } `json:"metadata"` + } + var unmarshalledInfo infoJSON + result, err := sonic.Marshal(&info) require.Nil(t, err) - expected := `{"name":"Test Template Name","author":["forgedhallpass","ice3man"],"tags":["cve","misc"],"description":"Test description","reference":"Reference1","severity":"high","metadata":{"string_key":"string_value","array_key":["array_value1","array_value2"],"map_key":{"key1":"val1"}}}` - require.Equal(t, expected, string(result)) + err = sonic.Unmarshal(result, &unmarshalledInfo) + require.Nil(t, err) + + expected := infoJSON{ + Name: "Test Template Name", + Author: []string{"forgedhallpass", "ice3man"}, + Tags: []string{"cve", "misc"}, + Description: "Test description", + Reference: "Reference1", + Severity: "high", + Metadata: struct { + StringKey string `json:"string_key"` + ArrayKey []string `json:"array_key"` + MapKey interface{} `json:"map_key"` + }{ + StringKey: "string_value", + ArrayKey: []string{"array_value1", "array_value2"}, + MapKey: map[string]interface{}{ + "key1": "val1", + }, + }, + } + + require.Equal(t, expected, unmarshalledInfo) } func TestInfoYamlMarshal(t *testing.T) {