internal/report: add LintOffline function
Add LintOffline function which performs all lint checks that can
be done without a network connection.
Use this offline function in short mode for TestLintAllReports. This means
most issues will be caught before submit.
We could alternatively use the mock proxy test framework here,
but that would be hard to maintain because reports are added/changed
frequently.
Change-Id: Ia4f1fdf0d306d08737ae2d8fa52540a51c2c3ffa
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/524137
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/all_test.go b/all_test.go
index a5941e8..ba42de8 100644
--- a/all_test.go
+++ b/all_test.go
@@ -44,9 +44,6 @@
}
func TestLintReports(t *testing.T) {
- if testing.Short() {
- t.Skip("skipping test that uses internet in short mode")
- }
if runtime.GOOS == "android" {
t.Skipf("android builder does not have access to reports/")
}
@@ -72,10 +69,23 @@
reports = append(reports, filename)
}
}
+
+ // Skip network calls in short mode.
+ var lint func(r *report.Report) []string
+ if testing.Short() {
+ lint = func(r *report.Report) []string {
+ return r.LintOffline()
+ }
+ } else {
+ pc := proxy.DefaultClient
+ lint = func(r *report.Report) []string {
+ return r.Lint(pc)
+ }
+ }
+
// Map from aliases (CVEs/GHSAS) to report paths, used to check for duplicate aliases.
aliases := make(map[string]string)
sort.Strings(reports)
- pc := proxy.DefaultClient
for _, filename := range reports {
t.Run(filename, func(t *testing.T) {
r, err := report.Read(filename)
@@ -85,7 +95,7 @@
if err := r.CheckFilename(filename); err != nil {
t.Error(err)
}
- lints := r.Lint(pc)
+ lints := lint(r)
if len(lints) > 0 {
t.Errorf(strings.Join(lints, "\n"))
}