diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-01-31 18:37:12 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-01-31 18:37:12 -0500 |
commit | 531c15b6c5f6c3d274ffec11a15b0ad22d685a90 (patch) | |
tree | f6bb3c61fc70819ae37e8a2390010fe5592754cb /internal | |
parent | f77d9ce238dc4c86a605770b33f27d2cb0d51eb3 (diff) | |
download | cvez-531c15b6c5f6c3d274ffec11a15b0ad22d685a90.tar.bz2 cvez-531c15b6c5f6c3d274ffec11a15b0ad22d685a90.zip |
move feed tests to internal/feed/feed_test.go, add internal/feed/testdata
Diffstat (limited to 'internal')
-rw-r--r-- | internal/feed/feed_test.go | 56 | ||||
-rw-r--r-- | internal/feed/testdata/nvdcve-1.1-2003.json.gz | bin | 0 -> 434020 bytes | |||
-rw-r--r-- | internal/feed/testdata/nvdcve-1.1-2021.json.gz | bin | 0 -> 4852632 bytes | |||
-rw-r--r-- | internal/feed/testdata/nvdcve-1.1-modified.json.gz | bin | 0 -> 288574 bytes |
4 files changed, 56 insertions, 0 deletions
diff --git a/internal/feed/feed_test.go b/internal/feed/feed_test.go new file mode 100644 index 0000000..f31a3ae --- /dev/null +++ b/internal/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) +// } +} + diff --git a/internal/feed/testdata/nvdcve-1.1-2003.json.gz b/internal/feed/testdata/nvdcve-1.1-2003.json.gz Binary files differnew file mode 100644 index 0000000..c7796a6 --- /dev/null +++ b/internal/feed/testdata/nvdcve-1.1-2003.json.gz diff --git a/internal/feed/testdata/nvdcve-1.1-2021.json.gz b/internal/feed/testdata/nvdcve-1.1-2021.json.gz Binary files differnew file mode 100644 index 0000000..83ca5e6 --- /dev/null +++ b/internal/feed/testdata/nvdcve-1.1-2021.json.gz diff --git a/internal/feed/testdata/nvdcve-1.1-modified.json.gz b/internal/feed/testdata/nvdcve-1.1-modified.json.gz Binary files differnew file mode 100644 index 0000000..c675fb6 --- /dev/null +++ b/internal/feed/testdata/nvdcve-1.1-modified.json.gz |