aboutsummaryrefslogtreecommitdiff
path: root/internal/testing/sample/sample.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-02-19 08:41:12 -0500
committerJonathan Amsterdam <jba@google.com>2021-02-19 21:45:42 +0000
commit98ffe01caf418206168dc9f9eb34733315dce3e6 (patch)
treee8a17030b3bea4702567314e7b2b09cb1db0f553 /internal/testing/sample/sample.go
parent8680fdf5411ee5f6dc4f785304b97301e3e70388 (diff)
downloadgo-x-pkgsite-98ffe01caf418206168dc9f9eb34733315dce3e6.tar.xz
internal/testing/sample: make a fresh copy of Imports
Create a new slice of imports each time it's used. This ensures that memory isn't shared between sample modules. It addresses a race condition we saw when running postgres tests concurrently. Change-Id: I0c1e0112ff7b944433565c7cacdd7226a32ad4eb Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/294149 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/testing/sample/sample.go')
-rw-r--r--internal/testing/sample/sample.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go
index 0418be09..d4ffff0e 100644
--- a/internal/testing/sample/sample.go
+++ b/internal/testing/sample/sample.go
@@ -47,7 +47,6 @@ var (
Suffix = "foo"
PackagePath = path.Join(ModulePath, Suffix)
V1Path = PackagePath
- Imports = []string{"path/to/bar", "fmt"}
ReadmeFilePath = "README.md"
ReadmeContents = "readme"
GOOS = internal.All
@@ -203,12 +202,13 @@ func UnitForModuleRoot(m *internal.ModuleInfo) *internal.Unit {
func UnitForPackage(path, modulePath, version, name string, isRedistributable bool) *internal.Unit {
// Copy Doc because some tests modify it.
doc := *Doc
+ imps := Imports()
return &internal.Unit{
UnitMeta: *UnitMeta(path, modulePath, version, name, isRedistributable),
Documentation: []*internal.Documentation{&doc},
LicenseContents: Licenses(),
- Imports: Imports,
- NumImports: len(Imports),
+ Imports: imps,
+ NumImports: len(imps),
}
}
@@ -380,3 +380,7 @@ func Licenses() []*licenses.License {
{Metadata: LicenseMetadata()[0], Contents: []byte(`Lorem Ipsum`)},
}
}
+
+func Imports() []string {
+ return []string{"fmt", "path/to/bar"}
+}