Skip to content

Commit

Permalink
Add parseContext() test
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Aug 17, 2023
1 parent 8bf7edb commit c4df4e8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/vex/vex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,24 @@ func TestParse(t *testing.T) {
require.Equal(t, vulns, tc.vulns, m)
}
}

func TestParseContext(t *testing.T) {
for tCase, tc := range map[string]struct {
docData string
expected string
shouldErr bool
}{
"Normal": {`{"@context": "https://openvex.dev/ns"}`, "https://openvex.dev/ns", false},
"Other JSON": {`{"document": { "category": "csaf_vex" } }`, "", false},
"Invalid JSON": {`@context": "https://openvex.dev/ns`, "", true},
"Other json-ld": {`{"@context": "https://spdx.dev/"}`, "", false},
} {
res, err := parseContext([]byte(tc.docData))
if tc.shouldErr {
require.Error(t, err, tCase)
continue
}
require.NoError(t, err, tCase)
require.Equal(t, res, tc.expected, tCase)
}
}

0 comments on commit c4df4e8

Please sign in to comment.