aboutsummaryrefslogtreecommitdiff
path: root/feed/feed_test.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-04 00:35:31 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-04 00:35:31 -0500
commit9c17b97cd0f83be3fff9fa4e87fd1d29052ea616 (patch)
tree0d97030a0d0c3ad983be281ce89f80571338887f /feed/feed_test.go
parent92400d731546557d110c9c3cc3906d700f83dda8 (diff)
downloadcvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.tar.bz2
cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.zip
rename to github.com/pablotron/cvez, remove internal libs
Diffstat (limited to 'feed/feed_test.go')
-rw-r--r--feed/feed_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/feed/feed_test.go b/feed/feed_test.go
new file mode 100644
index 0000000..f31a3ae
--- /dev/null
+++ b/feed/feed_test.go
@@ -0,0 +1,56 @@
+package feed
+
+import (
+ "compress/gzip"
+ "encoding/json"
+ "io"
+ // "fmt"
+ "os"
+ "testing"
+)
+
+func openTest(path string) (io.Reader, error) {
+ // open file for reading
+ file, err := os.Open(path)
+ if err != nil {
+ return nil, err
+ }
+
+ // wrap in reader, return success
+ return gzip.NewReader(file)
+}
+
+// Test feed parser
+func TestFeedParser(t *testing.T) {
+ t.Run("TestUnmarshalJSON", func(t *testing.T) {
+ var f Feed
+
+ // read test data, check for error
+ src, err := openTest("testdata/nvdcve-1.1-2021.json.gz")
+ if err != nil {
+ t.Error(err)
+ }
+
+ // decode cve feed, check for error
+ d := json.NewDecoder(src)
+ if err := d.Decode(&f); err != nil {
+ t.Error(err)
+ }
+ })
+// var f Feed
+//
+// // decode cve feed
+// d := json.NewDecoder(os.Stdin)
+// if err := d.Decode(&f); err != nil {
+// t.Error(err)
+// }
+//
+// var dst bytes.Buffer
+//
+// // create json encoder
+// e := json.NewEncoder(&dst)
+// if err := e.Encode(f); err != nil {
+// t.Error(err)
+// }
+}
+