internal/postgres: fail on attempt to insert doc with empty GOOS/GOARCH

We should never insert documentation with an empty GOOS/GOARCH pair.

For golang/go#44048

Change-Id: Ie4ccd881bb9441f523bada08e5ee8cf30f68b8f3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/288512
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/internal/frontend/search_test.go b/internal/frontend/search_test.go
index 6375ae0..108075a 100644
--- a/internal/frontend/search_test.go
+++ b/internal/frontend/search_test.go
@@ -43,6 +43,8 @@
 						IsRedistributable: true,
 					},
 					Documentation: &internal.Documentation{
+						GOOS:     sample.GOOS,
+						GOARCH:   sample.GOARCH,
 						Synopsis: "foo is a package.",
 						Source:   []byte{},
 					},
@@ -72,6 +74,8 @@
 						IsRedistributable: true,
 					},
 					Documentation: &internal.Documentation{
+						GOOS:     sample.GOOS,
+						GOARCH:   sample.GOARCH,
 						Synopsis: "bar is used by foo.",
 						Source:   []byte{},
 					},
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 2d84be8..f629187 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -466,6 +466,9 @@
 			continue
 		}
 		unitID := pathToUnitID[path]
+		if doc.GOOS == "" || doc.GOARCH == "" {
+			return errors.New("empty GOOS or GOARCH")
+		}
 		docValues = append(docValues, unitID, doc.GOOS, doc.GOARCH, doc.Synopsis, doc.Source)
 	}
 	uniqueCols := []string{"unit_id", "goos", "goarch"}
diff --git a/internal/postgres/search_test.go b/internal/postgres/search_test.go
index f8b2a4c..1a830ec 100644
--- a/internal/postgres/search_test.go
+++ b/internal/postgres/search_test.go
@@ -419,6 +419,8 @@
 				IsRedistributable: true, // required because some test cases depend on the README contents
 			},
 			Documentation: &internal.Documentation{
+				GOOS:     sample.GOOS,
+				GOARCH:   sample.GOARCH,
 				Synopsis: "Package cloud contains a library and tools for open cloud development in Go. The Go Cloud Development Kit (Go CDK)",
 				Source:   []byte{},
 			},
@@ -432,6 +434,8 @@
 				IsRedistributable: true, // required because some test cases depend on the README contents
 			},
 			Documentation: &internal.Documentation{
+				GOOS:     sample.GOOS,
+				GOARCH:   sample.GOARCH,
 				Synopsis: "Package client-go implements a Go client for Kubernetes.",
 				Source:   []byte{},
 			},