diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
commit | 9c17b97cd0f83be3fff9fa4e87fd1d29052ea616 (patch) | |
tree | 0d97030a0d0c3ad983be281ce89f80571338887f /internal/cpe/v23binding_test.go | |
parent | 92400d731546557d110c9c3cc3906d700f83dda8 (diff) | |
download | cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.tar.bz2 cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.zip |
rename to github.com/pablotron/cvez, remove internal libs
Diffstat (limited to 'internal/cpe/v23binding_test.go')
-rw-r--r-- | internal/cpe/v23binding_test.go | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/internal/cpe/v23binding_test.go b/internal/cpe/v23binding_test.go deleted file mode 100644 index 4fa46bb..0000000 --- a/internal/cpe/v23binding_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package cpe - -import ( - "encoding/json" - "testing" -) - -func TestNewV23Binding(t *testing.T) { - passTests := []string { - "cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*", - } - - for _, val := range(passTests) { - t.Run(val, func(t *testing.T) { - if _, err := NewV23Binding(val); err != nil { - t.Error(err) - } - }) - } - - failTests := []struct { - val string - exp string - } {{ - val: "o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*", - exp: "missing CPE 2.3 prefix", - }, { - val: "cpe:2.3:\n", - exp: "invalid byte: 0x0a", - }, { - val: "cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*", - exp: "invalid attribute count: 10 != 11", - }, { - val: "cpe:2.3:foo:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*", - exp: "unknown part: \"foo\"", - }} - - for _, test := range(failTests) { - t.Run(test.val, func(t *testing.T) { - got, err := NewV23Binding(test.val) - if 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) - } - }) - } -} - -func TestV23BindingString(t *testing.T) { - tests := []string { - "cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*", - } - - for _, val := range(tests) { - t.Run(val, func(t *testing.T) { - if got, err := NewV23Binding(val); err != nil { - t.Error(err) - } else if got.String() != val { - t.Errorf("got \"%s\", exp \"%s\"", got.String(), val) - } - }) - } -} - -func TestV23BindingUnmarshalJSON(t *testing.T) { - passTests := []string { - `"cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*"`, - } - - for _, val := range(passTests) { - t.Run(val, func(t *testing.T) { - var b V23Binding - if err := json.Unmarshal([]byte(val), &b); err != nil { - t.Error(err) - } - }) - } - - failTests := []struct { - val string - exp string - } {{ - val: `"o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*`, - exp: "unexpected end of JSON input", - }, { - val: `"o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*"`, - exp: "missing CPE 2.3 prefix", - }} - - 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 { - t.Errorf("got %v, exp error", got) - } else if err.Error() != test.exp { - t.Errorf("got \"%s\", exp \"%s\"", err.Error(), test.exp) - } - }) - } -} - -func TestV23BindingMarshalJSON(t *testing.T) { - tests := []string { - "cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*", - } - - for _, val := range(tests) { - t.Run(val, func(t *testing.T) { - // create binding, check for error - b, err := NewV23Binding(val) - if err != nil { - t.Error(err) - return - } - - // marshal json, check for error - got, err := json.Marshal(b) - if err != nil { - t.Error(err) - return - } - - // build/check expected value - exp := "\"" + val + "\"" - if string(got) != exp { - t.Errorf("got \"%s\", exp \"%s\"", string(got), exp) - return - } - }) - } -} |