diff options
Diffstat (limited to 'nvdmirror/nvdmirror_test.go')
-rw-r--r-- | nvdmirror/nvdmirror_test.go | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/nvdmirror/nvdmirror_test.go b/nvdmirror/nvdmirror_test.go index 5b40dd8..2c65d41 100644 --- a/nvdmirror/nvdmirror_test.go +++ b/nvdmirror/nvdmirror_test.go @@ -60,22 +60,67 @@ func TestSync(t *testing.T) { // custom sync config // FIXME: stand up custom server for this - urls := Urls { - Cve11Base: fmt.Sprintf("http://localhost:%d", port), + config := SyncConfig { + Cve11BaseUrl: fmt.Sprintf("http://localhost:%d", port), } // sync data - if err := Sync(urls, &cache, dir); err != nil { - t.Error(err) - } + t.Run("initial", func(t *testing.T) { + if err := Sync(config, &cache, dir); err != nil { + t.Error(err) + } + }) // sync data again (to test caching) - if err := Sync(urls, &cache, dir); err != nil { - t.Error(err) - } + t.Run("caching", func(t *testing.T) { + if err := Sync(config, &cache, dir); err != nil { + t.Error(err) + } + }) + + // sync w/ missing dir + t.Run("missingDir", func(t *testing.T) { + missingDir := filepath.Join(dir, "does/not/exist") + if err := Sync(config, &cache, missingDir); err != nil { + t.Error(err) + } + }) + + // sync w/ bad cache + t.Run("failSetCache", func(t *testing.T) { + var cache FailSetCache + if err := Sync(config, &cache, dir); err == nil { + t.Error(err) + } + }) + + t.Run("customUserAgent", func(t *testing.T) { + // custom sync config + // FIXME: stand up custom server for this + config := SyncConfig { + Cve11BaseUrl: fmt.Sprintf("http://localhost:%d", port), + UserAgent: "custom-user-agent/0.0.0", + } + + if err := Sync(config, &cache, dir); err != nil { + t.Error(err) + } + }) + + t.Run("clientFail", func(t *testing.T) { + // custom sync config + // FIXME: stand up custom server for this + config := SyncConfig { + Cve11BaseUrl: "http://localhost:0", + } + + if err := Sync(config, &cache, dir); err != nil { + t.Error(err) + } + }) } -func TestBadUrl(t *testing.T) { +func TestBadUrls(t *testing.T) { // create temp dir dir, err := os.MkdirTemp("", "") if err != nil { @@ -92,19 +137,21 @@ func TestBadUrl(t *testing.T) { } defer cache.Close() + // invalid base URLs failTests := []string { - "httsldkfjasldkfjadp://localhost:0", - "http://localhost:0", + "httsldkfjasldkfjadp:// \\ localhost:0", } for _, test := range(failTests) { t.Run(test, func(t *testing.T) { // custom sync config - urls := Urls { Cve11Base: test } + config := SyncConfig { Cve11BaseUrl: test } - // sync data - if err := Sync(urls, &cache, dir); err == nil { - t.Errorf("got success, exp error") + // sync data; note: even with an invalid base URL we still expect + // this call to succeed; it's just that all of the URLs will be + // nonsensical + if err := Sync(config, &cache, dir); err != nil { + t.Error(err) } }) } |