From 64aecc1326893b477b570c7261e0c5eb63cbd98c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 26 Feb 2022 00:15:41 -0500 Subject: cpe/v23binding_test.go: fix TestV23BindingUnmarshalJSON() --- cpe/v23binding_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3