Skip to content

Proxy: Harden internal/env tests and add counterfeiter fakes. v7.0.144#4665

Merged
winlinvip merged 5 commits into
ossrs:developfrom
winlinvip:develop
Apr 19, 2026
Merged

Proxy: Harden internal/env tests and add counterfeiter fakes. v7.0.144#4665
winlinvip merged 5 commits into
ossrs:developfrom
winlinvip:develop

Conversation

@winlinvip
Copy link
Copy Markdown
Member

  • Refactor internal/env for testability. Route every os/filesystem
    call in env.go through swappable package-level function variables
    (getEnv, setEnv, lookupEnv, openFile). Split parseEnvFile into a
    thin file-opening wrapper plus a pure parseEnvReader(io.Reader) so the
    parser can be tested directly without touching disk.
  • Hermetic tests, 96.9% coverage. Rewrite internal/env/env_test.go to
    install in-memory fakes via withFakeEnv / withFakeOpen helpers that
    swap the package vars and restore them on t.Cleanup. Tests no longer
    mutate real process env or write temp .env files, removing a source of
    flakiness under parallel test execution. New cases cover NewEnvironment,
    setEnvDefault, loadEnvFile error paths, and edge cases in the parser.
  • Counterfeiter-based fake generation. Add counterfeiter as a Go tool
    dependency, a //go:generate directive for the Environment interface
    (internal/env/gen.go), and commit the generated
    internal/env/envfakes/fake_environment.go so downstream packages can
    test against a spec-faithful fake instead of hand-rolling stubs. Expose
    the step as make generate.
  • Tooling. scripts/proxy-utest.sh gains a --coverage / -c flag
    that runs go test -coverprofile=... across ./cmd/... and
    ./internal/... and prints per-function coverage via go tool cover -func. The srs-develop skill doc is updated to include the
    regenerate-fakes step and the new coverage flag.
  • Go version. Bump go.mod to Go 1.25 (required for the go tool
    directive used to pin the counterfeiter CLI as a tool dep).

winlinvip and others added 4 commits April 18, 2026 09:21
…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>
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Apr 19, 2026
…n. v7.0.144 (ossrs#4665)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@winlinvip winlinvip changed the title Proxy: Harden internal/env tests and add counterfeiter fakes Proxy: Harden internal/env tests and add counterfeiter fakes. v7.0.144 Apr 19, 2026
@winlinvip winlinvip merged commit cd11a67 into ossrs:develop Apr 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EnglishNative This issue is conveyed exclusively in English.

Development

Successfully merging this pull request may close these issues.

1 participant