aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/datatype_test.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-01 01:10:24 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-01 01:10:24 -0500
commita824a9732154f9bee2ce530f753d5747de78aa3f (patch)
treea24aac9ae339d7a62b9ec170c0c27a7cd84e481d /internal/feed/datatype_test.go
parent94b148ccdcb88f2544c222f73f5c734ac78ccd96 (diff)
downloadcvez-a824a9732154f9bee2ce530f753d5747de78aa3f.tar.bz2
cvez-a824a9732154f9bee2ce530f753d5747de78aa3f.zip
internal/feed: split out datatype, add tests
Diffstat (limited to 'internal/feed/datatype_test.go')
-rw-r--r--internal/feed/datatype_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/feed/datatype_test.go b/internal/feed/datatype_test.go
new file mode 100644
index 0000000..05f6a74
--- /dev/null
+++ b/internal/feed/datatype_test.go
@@ -0,0 +1,65 @@
+package feed
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+func TestDataTypeUnmarshalInvalidData(t *testing.T) {
+ test := []byte(`{}`)
+ var val DataType
+
+ if err := json.Unmarshal(test, &val); err == nil {
+ t.Errorf("got \"%s\", exp error", val)
+ }
+}
+
+func TestDataTypeUnmarshalUnknown(t *testing.T) {
+ test := []byte(`"foo"`)
+ exp := "unknown data type: foo"
+ var val DataType
+
+ err := json.Unmarshal(test, &val)
+ if err == nil {
+ t.Errorf("got \"%s\", exp error", val)
+ return
+ }
+
+ if err.Error() != exp {
+ t.Errorf("got \"%s\", exp \"%s\"", err.Error(), exp)
+ }
+}
+
+func TestDataTypeUnmarshalValid(t *testing.T) {
+ test := []byte(`"CVE"`)
+ exp := CveType
+ var got DataType
+
+ if err := json.Unmarshal(test, &got); err != nil {
+ t.Error(err)
+ return
+ }
+
+ if got != exp {
+ t.Errorf("got \"%s\", exp \"%s\"", got, exp)
+ }
+}
+
+func TestDataTypeString(t *testing.T) {
+ tests := []struct {
+ val DataType
+ exp string
+ } {
+ { CveType, "CVE" },
+ { DataType(255), "DataType(255)" },
+ }
+
+ for _, test := range(tests) {
+ t.Run(test.val.String(), func(t *testing.T) {
+ got := test.val.String()
+ if got != test.exp {
+ t.Errorf("got \"%s\", exp \"%s\"", got, test.exp)
+ }
+ })
+ }
+}