diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-26 00:15:41 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-26 00:15:41 -0500 |
commit | 64aecc1326893b477b570c7261e0c5eb63cbd98c (patch) | |
tree | e34b75d5dd9b1d51a91c60d599ac109e9ea9218f | |
parent | a70582d75acb9989d218511ae130ea4daaed83d0 (diff) | |
download | cvez-64aecc1326893b477b570c7261e0c5eb63cbd98c.tar.bz2 cvez-64aecc1326893b477b570c7261e0c5eb63cbd98c.zip |
cpe/v23binding_test.go: fix TestV23BindingUnmarshalJSON()
-rw-r--r-- | cpe/v23binding_test.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cpe/v23binding_test.go b/cpe/v23binding_test.go index 4fa46bb..3030fbe 100644 --- a/cpe/v23binding_test.go +++ b/cpe/v23binding_test.go @@ -86,12 +86,19 @@ func TestV23BindingUnmarshalJSON(t *testing.T) { }, { val: `"o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*"`, exp: "missing CPE 2.3 prefix", + }, { + val: `x`, + exp: "invalid character 'x' looking for beginning of value", }} for _, test := range(failTests) { t.Run(test.val, func(t *testing.T) { var got V23Binding - if err := json.Unmarshal([]byte(test.val), &got); err == nil { + + // NOTE: we use got.UnmarshalJSON() instead of json.Unmarshal(), + // because if we use the latter with invalid json it fails before + // testing the underlying method. + if err := got.UnmarshalJSON([]byte(test.val)); err == nil { t.Errorf("got %v, exp error", got) } else if err.Error() != test.exp { t.Errorf("got \"%s\", exp \"%s\"", err.Error(), test.exp) |