Skip to content

Commit 0675147

Browse files
committed
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 <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent 55ac839 commit 0675147

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

internal/frontend/search_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func TestFetchSearchPage(t *testing.T) {
4343
IsRedistributable: true,
4444
},
4545
Documentation: &internal.Documentation{
46+
GOOS: sample.GOOS,
47+
GOARCH: sample.GOARCH,
4648
Synopsis: "foo is a package.",
4749
Source: []byte{},
4850
},
@@ -72,6 +74,8 @@ func TestFetchSearchPage(t *testing.T) {
7274
IsRedistributable: true,
7375
},
7476
Documentation: &internal.Documentation{
77+
GOOS: sample.GOOS,
78+
GOARCH: sample.GOARCH,
7579
Synopsis: "bar is used by foo.",
7680
Source: []byte{},
7781
},

internal/postgres/insert_module.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ func insertDoc(ctx context.Context, db *database.DB,
466466
continue
467467
}
468468
unitID := pathToUnitID[path]
469+
if doc.GOOS == "" || doc.GOARCH == "" {
470+
return errors.New("empty GOOS or GOARCH")
471+
}
469472
docValues = append(docValues, unitID, doc.GOOS, doc.GOARCH, doc.Synopsis, doc.Source)
470473
}
471474
uniqueCols := []string{"unit_id", "goos", "goarch"}

internal/postgres/search_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
419419
IsRedistributable: true, // required because some test cases depend on the README contents
420420
},
421421
Documentation: &internal.Documentation{
422+
GOOS: sample.GOOS,
423+
GOARCH: sample.GOARCH,
422424
Synopsis: "Package cloud contains a library and tools for open cloud development in Go. The Go Cloud Development Kit (Go CDK)",
423425
Source: []byte{},
424426
},
@@ -432,6 +434,8 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
432434
IsRedistributable: true, // required because some test cases depend on the README contents
433435
},
434436
Documentation: &internal.Documentation{
437+
GOOS: sample.GOOS,
438+
GOARCH: sample.GOARCH,
435439
Synopsis: "Package client-go implements a Go client for Kubernetes.",
436440
Source: []byte{},
437441
},

0 commit comments

Comments
 (0)