Skip to content

goproxytest: add overlay capability#304

Merged
rogpeppe merged 1 commit into
masterfrom
051-goproxytest-overlay
Apr 17, 2026
Merged

goproxytest: add overlay capability#304
rogpeppe merged 1 commit into
masterfrom
051-goproxytest-overlay

Conversation

@rogpeppe

Copy link
Copy Markdown
Owner

It's useful to have a hybrid mode where some modules are served from the txtar contents but others come from the regular Go sources. We make goproxytest
capable of doing that: adding a file named OVERLAY to the top level .gomodproxy directory triggers that behavior.

Comment thread gotooltest/setup.go
}
if err := json.Unmarshal(eout.Bytes(), &goEnv); err != nil {
return fmt.Errorf("failed to unmarshal GOROOT and GOCACHE tags from go command out: %v\n%v", err, eout)
if err := goenv.Unmarshal(&goEnv); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this is a mild regression; you're now asking for all env vars, even though before we only fetched three. You could add names ...string to keep this in place, meaning that if the caller doesn't give any, all are fetched at extra cost.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that approach won't reduce the number of calls when two calls to goenv.Unmarshal both ask for distinct subsets of the variables. I've changed things so that we explicitly ask for all the env vars we might need - that's OK because this is an internal package and we know all the callers, and none of the variables are costly to calculate.

We want to be able to use regular Go
modules as well as test-related ones.
The contents of this file are ignored; only
its presence is necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap this at 80-100 columns as usual, i.e. two lines. no need for four lines AFAICT

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread goproxytest/setup.go Outdated
// the server when the test completes.
//
// If a file exists in the top level of the [GoModProxyDir] directory
// named "OVERLAY", then instead of replacing the Go proxy entirely, the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that GoModProxyDir is .gomodproxy, I find the name OVERLAY a bit inconsistent and unnecessarily loud. Almost like it means to be an env var when it's not. I'd personally just go with overlay. It can't possibly be confused with a modulepath_version name.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone with _enable_overlay as discussed online

Comment thread goproxytest/setup.go Outdated
env.Defer(srv.Close)
// Add GOPROXY after calling the original setup
// so that it overrides any GOPROXY set there.
// Look for local test modules first, falling back to the existing download cache.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Look for local test modules first, falling back to the existing download cache.
// Look for local test modules first, falling back to the existing module download cache.

for the sake of consistent naming with the Go docs

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread goproxytest/setup.go Outdated
// be relying on modules that match them, but it seems safer
// to do this.
"GONOPROXY="+goEnv.GONOPROXY,
"GOPRIVATE="+goEnv.GOPRIVATE,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwarding GOPRIVATE is unnecessary; go env already shows how it propagates to the others:

$ GOPRIVATE=foobar go env | grep foobar
GONOPROXY='foobar'
GONOSUMDB='foobar'
GOPRIVATE='foobar'

We weren't passing it along before, and we don't need to pass it along for this, so I'd keep omitting it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rogpeppe rogpeppe force-pushed the 051-goproxytest-overlay branch 2 times, most recently from 91ab28f to 4dd8d2a Compare April 17, 2026 08:04
It's useful to have a hybrid mode where some modules
are served from the txtar contents but others come
from the regular Go sources. We make goproxytest
capable of doing that: adding a file named `OVERLAY`
to the top level `.gomodproxy` directory triggers that
behavior.

Also standardize the log messages produced by goproxytest
to make it clear in all cases where the logs are coming from,
and remove the "no archive" log because that's more
common in overlay mode and doesn't provide much useful
information.
@rogpeppe rogpeppe force-pushed the 051-goproxytest-overlay branch from 4dd8d2a to b37cb59 Compare April 17, 2026 08:15
@rogpeppe rogpeppe merged commit 02e5dd4 into master Apr 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants