Isolate synthetic module downloads in workflow tests
This commit is contained in:
@@ -150,6 +150,19 @@ func TestWoodpeckerTagDeliveryTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWoodpeckerTagDeliveryUsesTaggedModuleVersion(t *testing.T) {
|
||||
// Synthetic downloads must leave the caller's module cache untouched.
|
||||
callerCache := t.TempDir()
|
||||
t.Setenv("GOMODCACHE", callerCache)
|
||||
t.Cleanup(func() {
|
||||
entries, err := os.ReadDir(callerCache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("synthetic module downloads modified the caller's cache: %v", entries)
|
||||
}
|
||||
})
|
||||
|
||||
root := cliRepositoryRoot(t)
|
||||
contents, err := os.ReadFile(filepath.Join(root, "examples", "woodpecker", "tag-delivery.yml"))
|
||||
if err != nil {
|
||||
@@ -185,7 +198,7 @@ func TestWoodpeckerTagDeliveryUsesTaggedModuleVersion(t *testing.T) {
|
||||
moduleBefore := readWoodpeckerFixtureFile(t, filepath.Join(repository, "go.mod"))
|
||||
commit := oldCommit
|
||||
env := templateEnvironment(repository, commit, goDir, goLog)
|
||||
env["GOPROXY"] = "file://" + filepath.ToSlash(proxy)
|
||||
useSyntheticModuleProxy(t, env, "file://"+filepath.ToSlash(proxy))
|
||||
sumLog := filepath.Join(t.TempDir(), "tool-only-sums")
|
||||
env["RELEASEKIT_SUM_LOG"] = sumLog
|
||||
output := runWoodpeckerBlock(t, command, repository, env)
|
||||
@@ -207,7 +220,7 @@ func TestWoodpeckerTagDeliveryUsesTaggedModuleVersion(t *testing.T) {
|
||||
commit := pushTaggedCLIRepository(t, repository)
|
||||
moduleBefore := readWoodpeckerFixtureFile(t, filepath.Join(repository, "go.mod"))
|
||||
env := templateEnvironment(repository, commit, goDir, goLog)
|
||||
env["GOPROXY"] = "file://" + filepath.ToSlash(proxy)
|
||||
useSyntheticModuleProxy(t, env, "file://"+filepath.ToSlash(proxy))
|
||||
sumLog := filepath.Join(t.TempDir(), "tool-only-sums")
|
||||
env["RELEASEKIT_SUM_LOG"] = sumLog
|
||||
output := runWoodpeckerBlock(t, command, repository, env)
|
||||
@@ -245,21 +258,15 @@ func TestWoodpeckerSourceDeliveryTemplateSelfBootstraps(t *testing.T) {
|
||||
defer proxy.Close()
|
||||
writeRepositoryFile(t, repository, "go.mod", "module example.com/cli-candidate\n\ngo 1.25.0\n\nrequire "+dependency+" v1.0.0\n")
|
||||
writeRepositoryFile(t, repository, "cmd/releasekit/main.go", "package main\n\nimport (\"fmt\"; \"os\"; helper \""+dependency+"\")\n\nfunc main() {\n\tfmt.Println(\"self-bootstrap \" + helper.Message)\n\tfmt.Printf(\"tool-args=%q\\n\", os.Args[1:])\n}\n")
|
||||
preparationEnv := map[string]string{
|
||||
"GOPROXY": proxy.URL, "GOSUMDB": "off", "GONOPROXY": "none", "GOPRIVATE": "",
|
||||
"GOWORK": "off", "GOTOOLCHAIN": "local", "GOENV": "off", "GOFLAGS": "-modcacherw",
|
||||
"GOMODCACHE": t.TempDir(),
|
||||
}
|
||||
preparationEnv := map[string]string{}
|
||||
useSyntheticModuleProxy(t, preparationEnv, proxy.URL)
|
||||
runWoodpeckerBlock(t, "go mod download "+dependency, repository, preparationEnv)
|
||||
cliGitRun(t, repository, "add", "cmd/releasekit/main.go", "go.mod", "go.sum")
|
||||
cliGitRun(t, repository, "commit", "-m", "add the self-bootstrapped command")
|
||||
commit := pushTaggedCLIRepository(t, repository)
|
||||
goDir, goLog := installGoBootstrapShim(t)
|
||||
env := templateEnvironment(repository, commit, goDir, goLog)
|
||||
for key, value := range preparationEnv {
|
||||
env[key] = value
|
||||
}
|
||||
env["GOMODCACHE"] = t.TempDir()
|
||||
useSyntheticModuleProxy(t, env, proxy.URL)
|
||||
proxyRequests.Store(0)
|
||||
env["CI_COMMIT_SHA"] = strings.Repeat("0", len(commit))
|
||||
if output, err := executeWoodpeckerBlock(command, repository, env); err == nil {
|
||||
@@ -426,6 +433,19 @@ esac
|
||||
return shimDir, goLog
|
||||
}
|
||||
|
||||
func useSyntheticModuleProxy(t *testing.T, environment map[string]string, proxyURL string) {
|
||||
t.Helper()
|
||||
environment["GOMODCACHE"] = t.TempDir()
|
||||
environment["GOPROXY"] = proxyURL
|
||||
environment["GOSUMDB"] = "off"
|
||||
environment["GONOPROXY"] = "none"
|
||||
environment["GOPRIVATE"] = ""
|
||||
environment["GOWORK"] = "off"
|
||||
environment["GOTOOLCHAIN"] = "local"
|
||||
environment["GOENV"] = "off"
|
||||
environment["GOFLAGS"] = "-modcacherw"
|
||||
}
|
||||
|
||||
func templateEnvironment(repository, commit, shimDir, goLog string) map[string]string {
|
||||
realGo, _ := exec.LookPath("go")
|
||||
return map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user