Skip to content

Commit

Permalink
test(model): compare the unmarshalled info
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Feb 1, 2025
1 parent 5ba8246 commit 0986e4c
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions pkg/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0986e4c

Please sign in to comment.