aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/dataformat_test.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-01 01:21:45 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-01 01:21:45 -0500
commit07390eeb960df3ca10b758c9f62459cf2ee9aa3f (patch)
tree6612ba4fe2f7252a3096bc2bb250aca11d86636f /internal/feed/dataformat_test.go
parenta824a9732154f9bee2ce530f753d5747de78aa3f (diff)
downloadcvez-07390eeb960df3ca10b758c9f62459cf2ee9aa3f.tar.bz2
cvez-07390eeb960df3ca10b758c9f62459cf2ee9aa3f.zip
add internal/feed/dataformat.go
Diffstat (limited to 'internal/feed/dataformat_test.go')
-rw-r--r--internal/feed/dataformat_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/feed/dataformat_test.go b/internal/feed/dataformat_test.go
new file mode 100644
index 0000000..efb4986
--- /dev/null
+++ b/internal/feed/dataformat_test.go
@@ -0,0 +1,65 @@
+package feed
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+func TestDataFormatUnmarshalInvalidData(t *testing.T) {
+ test := []byte(`{}`)
+ var val DataFormat
+
+ if err := json.Unmarshal(test, &val); err == nil {
+ t.Errorf("got \"%s\", exp error", val)
+ }
+}
+
+func TestDataFormatUnmarshalUnknown(t *testing.T) {
+ test := []byte(`"foo"`)
+ exp := "unknown data format: foo"
+ var val DataFormat
+
+ 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 TestDataFormatUnmarshalValid(t *testing.T) {
+ test := []byte(`"MITRE"`)
+ exp := MitreFormat
+ var got DataFormat
+
+ if err := json.Unmarshal(test, &got); err != nil {
+ t.Error(err)
+ return
+ }
+
+ if got != exp {
+ t.Errorf("got \"%s\", exp \"%s\"", got, exp)
+ }
+}
+
+func TestDataFormatString(t *testing.T) {
+ tests := []struct {
+ val DataFormat
+ exp string
+ } {
+ { MitreFormat, "MITRE" },
+ { DataFormat(255), "DataFormat(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)
+ }
+ })
+ }
+}