Proxy: Harden internal/env tests and add counterfeiter fakes. v7.0.144#4665
Merged
Conversation
…rage reporting Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…rallel misuse Adds direct tests for NewEnvironment, loadEnvFile, buildDefaultEnvironmentVariables, setEnvDefault, and all 22 Environment accessors. All env/cwd-touching tests now use t.Setenv or t.Chdir, which panic on t.Parallel() and prevent concurrent mutation of process-global state. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…irections Swap direct os.Getenv/Setenv/LookupEnv and os.Open calls in internal/env for package-level function variables so tests can replace them with in-memory fakes. Tests no longer mutate process env or hit the filesystem, making them safe to run in parallel and free of global side effects. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add `make generate` plus a counterfeiter tool dependency so test doubles for proxy interfaces can be produced consistently. Introduce the env package's //go:generate directive and its generated envfakes, and document the regenerate step in the srs-develop skill. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…n. v7.0.144 (ossrs#4665) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
internal/envfor testability. Route everyos/filesystemcall in
env.gothrough swappable package-level function variables(
getEnv,setEnv,lookupEnv,openFile). SplitparseEnvFileinto athin file-opening wrapper plus a pure
parseEnvReader(io.Reader)so theparser can be tested directly without touching disk.
internal/env/env_test.gotoinstall in-memory fakes via
withFakeEnv/withFakeOpenhelpers thatswap the package vars and restore them on
t.Cleanup. Tests no longermutate real process env or write temp
.envfiles, removing a source offlakiness under parallel test execution. New cases cover
NewEnvironment,setEnvDefault,loadEnvFileerror paths, and edge cases in the parser.counterfeiteras a Go tooldependency, a
//go:generatedirective for theEnvironmentinterface(
internal/env/gen.go), and commit the generatedinternal/env/envfakes/fake_environment.goso downstream packages cantest against a spec-faithful fake instead of hand-rolling stubs. Expose
the step as
make generate.scripts/proxy-utest.shgains a--coverage/-cflagthat runs
go test -coverprofile=...across./cmd/...and./internal/...and prints per-function coverage viago tool cover -func. Thesrs-developskill doc is updated to include theregenerate-fakes step and the new coverage flag.
go.modto Go 1.25 (required for thego tooldirective used to pin the counterfeiter CLI as a tool dep).