@@ -28,11 +28,48 @@ func TestInfoJsonMarshal(t *testing.T) {
2828 },
2929 }
3030
31+ type infoJSON struct {
32+ Name string `json:"name"`
33+ Author []string `json:"author"`
34+ Tags []string `json:"tags"`
35+ Description string `json:"description"`
36+ Reference string `json:"reference"`
37+ Severity string `json:"severity"`
38+ Metadata struct {
39+ StringKey string `json:"string_key"`
40+ ArrayKey []string `json:"array_key"`
41+ MapKey interface {} `json:"map_key"`
42+ } `json:"metadata"`
43+ }
44+ var unmarshalledInfo infoJSON
45+
3146 result , err := sonic .Marshal (& info )
3247 require .Nil (t , err )
3348
34- 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"}}}`
35- require .Equal (t , expected , string (result ))
49+ err = sonic .Unmarshal (result , & unmarshalledInfo )
50+ require .Nil (t , err )
51+
52+ expected := infoJSON {
53+ Name : "Test Template Name" ,
54+ Author : []string {"forgedhallpass" , "ice3man" },
55+ Tags : []string {"cve" , "misc" },
56+ Description : "Test description" ,
57+ Reference : "Reference1" ,
58+ Severity : "high" ,
59+ Metadata : struct {
60+ StringKey string `json:"string_key"`
61+ ArrayKey []string `json:"array_key"`
62+ MapKey interface {} `json:"map_key"`
63+ }{
64+ StringKey : "string_value" ,
65+ ArrayKey : []string {"array_value1" , "array_value2" },
66+ MapKey : map [string ]interface {}{
67+ "key1" : "val1" ,
68+ },
69+ },
70+ }
71+
72+ require .Equal (t , expected , unmarshalledInfo )
3673}
3774
3875func TestInfoYamlMarshal (t * testing.T ) {
0 commit comments