all_test: add check for duplicate summaries
Add a test to ensure that no two reports have the exact same summary.
This makes it easier for consumers to quickly visually/conceptually
distinguish reports beyond just the Go ID.
Change-Id: I00105570b5cd7ae5004788207ae61d4ca0deff8d
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/543801
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/all_test.go b/all_test.go
index 4436f8f..7a60a8d 100644
--- a/all_test.go
+++ b/all_test.go
@@ -89,6 +89,8 @@
// Map from aliases (CVEs/GHSAS) to report paths, used to check for duplicate aliases.
aliases := make(map[string]string)
+ // Map from summaries to report paths, used to check for duplicate summaries.
+ summaries := make(map[string]string)
sort.Strings(reports)
for _, filename := range reports {
t.Run(filename, func(t *testing.T) {
@@ -110,6 +112,13 @@
aliases[alias] = filename
}
}
+ if summary := r.Summary.String(); summary != "" {
+ if report, ok := summaries[summary]; ok {
+ t.Errorf("report %s shares duplicate summary %q with report %s", filename, summary, report)
+ } else {
+ summaries[summary] = filename
+ }
+ }
// Check that a correct OSV file was generated for each YAML report.
if r.Excluded == "" {
generated := r.ToOSV(time.Time{})