aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-02-16 15:50:14 -0500
committerJonathan Amsterdam <jba@google.com>2021-02-17 16:48:50 +0000
commit04cc7e6c0d128d1d1e2f1d07b49e5aff31a13698 (patch)
tree6a34e22357e660e4031adf46aea4b0326d3efdc1 /internal/postgres/insert_module_test.go
parentab25703ea40f4268f55a510dad8697f4b0a63ae4 (diff)
downloadgo-x-pkgsite-04cc7e6c0d128d1d1e2f1d07b49e5aff31a13698.tar.xz
internal/sample: improve treatment of sample licenses
To avoid sharing between tests, which can lead to race conditions, create new sample license slices and structs each time we need them. This uncovered some problems in the postgres tests. - The UpsertModule test was changing the top-level module license, but didn't propagate that change through all the units. We sample.ReplaceLicense to address that. - The checkModule was filling in missing license with defaults, instead of the correct data. Change-Id: I6074914155eb33d6ed6882f81a9d57b20135e422 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/292929 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>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 893f368c..44997549 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -101,11 +101,10 @@ func checkModule(ctx context.Context, t *testing.T, db *DB, want *internal.Modul
if err != nil {
t.Fatal(err)
}
- wantu.LicenseContents = sample.Licenses
var subdirectories []*internal.PackageMeta
for _, u := range want.Units {
if u.IsPackage() && (strings.HasPrefix(u.Path, wantu.Path) || wantu.Path == stdlib.ModulePath) {
- subdirectories = append(subdirectories, sample.PackageMeta(u.Path))
+ subdirectories = append(subdirectories, packageMetaFromUnit(u))
}
}
wantu.Subdirectories = subdirectories
@@ -119,6 +118,16 @@ func checkModule(ctx context.Context, t *testing.T, db *DB, want *internal.Modul
}
}
+func packageMetaFromUnit(u *internal.Unit) *internal.PackageMeta {
+ return &internal.PackageMeta{
+ Path: u.Path,
+ IsRedistributable: u.IsRedistributable,
+ Name: u.Name,
+ Synopsis: u.Documentation[0].Synopsis,
+ Licenses: u.Licenses,
+ }
+}
+
func TestInsertModuleLicenseCheck(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -188,7 +197,9 @@ func TestUpsertModule(t *testing.T) {
MustInsertModule(ctx, t, testDB, m)
// Change the module, and re-insert.
m.IsRedistributable = !m.IsRedistributable
- m.Licenses[0].Contents = append(m.Licenses[0].Contents, " and more"...)
+ lic := *m.Licenses[0]
+ lic.Contents = append(lic.Contents, " and more"...)
+ sample.ReplaceLicense(m, &lic)
m.Units[0].Readme.Contents += " and more"
MustInsertModule(ctx, t, testDB, m)