aboutsummaryrefslogtreecommitdiff
path: root/internal/cpe/v23binding_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cpe/v23binding_test.go')
-rw-r--r--internal/cpe/v23binding_test.go132
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
- }
- })
- }
-}