all: generate database from data/osv

Change-Id: Ib055df304582293c1c796de34427d40c3a6f623b
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/430683
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
diff --git a/all_test.go b/all_test.go
index 33bf037..2688a34 100644
--- a/all_test.go
+++ b/all_test.go
@@ -9,6 +9,7 @@
 
 import (
 	"errors"
+	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -16,7 +17,11 @@
 	"sort"
 	"strings"
 	"testing"
+	"time"
 
+	"github.com/google/go-cmp/cmp"
+	"github.com/google/go-cmp/cmp/cmpopts"
+	"golang.org/x/vulndb/internal/database"
 	"golang.org/x/vulndb/internal/report"
 )
 
@@ -89,6 +94,16 @@
 			if len(lints) > 0 {
 				t.Errorf(strings.Join(lints, "\n"))
 			}
+			if r.Excluded == "" {
+				e1 := database.GenerateOSVEntry(fn, time.Time{}, r)
+				e2, err := database.ReadOSV(fmt.Sprintf("data/osv/%v.json", e1.ID))
+				if err != nil {
+					t.Fatal(err)
+				}
+				if diff := cmp.Diff(e1, e2, cmpopts.EquateEmpty()); diff != "" {
+					t.Errorf("data/osv/%v.json does not match report:\n%v", e1.ID, diff)
+				}
+			}
 		})
 	}
 }