aboutsummaryrefslogtreecommitdiff
path: root/nvdmirror/nvdmirror_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'nvdmirror/nvdmirror_test.go')
-rw-r--r--nvdmirror/nvdmirror_test.go65
1 files changed, 28 insertions, 37 deletions
diff --git a/nvdmirror/nvdmirror_test.go b/nvdmirror/nvdmirror_test.go
index 2c65d41..fb9b56b 100644
--- a/nvdmirror/nvdmirror_test.go
+++ b/nvdmirror/nvdmirror_test.go
@@ -8,6 +8,18 @@ import (
"testing"
)
+// get test config
+func getTestConfig(port int) SyncConfig {
+ // build url
+ url := fmt.Sprintf("http://localhost:%d", port)
+
+ return SyncConfig {
+ Cve11BaseUrl: url,
+ CpeMatch10BaseUrl: url,
+ Cpe23DictUrl: fmt.Sprintf("%s/official-cpe-dictionary_v2.3.xml.gz", url),
+ }
+}
+
// serve on given port
func serve(port int, ch chan bool) {
s := http.Server {
@@ -59,64 +71,44 @@ func TestSync(t *testing.T) {
defer cache.Close()
// custom sync config
- // FIXME: stand up custom server for this
- config := SyncConfig {
- Cve11BaseUrl: fmt.Sprintf("http://localhost:%d", port),
- }
+ config := getTestConfig(port)
// sync data
t.Run("initial", func(t *testing.T) {
- if err := Sync(config, &cache, dir); err != nil {
- t.Error(err)
- }
+ Sync(config, &cache, dir)
})
// sync data again (to test caching)
t.Run("caching", func(t *testing.T) {
- if err := Sync(config, &cache, dir); err != nil {
- t.Error(err)
- }
+ Sync(config, &cache, dir)
})
// 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(config, &cache, missingDir)
})
// 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)
- }
+ Sync(config, &cache, dir)
})
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)
- }
+ config := getTestConfig(port)
+ config.UserAgent = "custom-user-agent/0.0.0"
+
+ Sync(config, &cache, dir)
})
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)
- }
+ config := getTestConfig(port)
+ config.Cve11BaseUrl = "http://localhost:0"
+
+ Sync(config, &cache, dir)
})
}
@@ -145,14 +137,13 @@ func TestBadUrls(t *testing.T) {
for _, test := range(failTests) {
t.Run(test, func(t *testing.T) {
// custom sync config
- config := SyncConfig { Cve11BaseUrl: test }
+ config := getTestConfig(0)
+ config.Cve11BaseUrl = test
// 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)
- }
+ Sync(config, &cache, dir)
})
}
}