#1540·hertz

TestRouteStaticFile leaves an untracked temporary file on Windows

Author: dajiaohuangCreated Aug 24, 2026Updated Aug 24, 2026

Describe the bug

Running TestRouteStaticFile on Windows passes, but leaves a randomly named untracked file in pkg/route. Repeated test runs accumulate additional files in the working tree.

The test creates its fixture with ioutil.TempFile(testRoot, ""). The StaticFS handler caches the opened file, so the deferred os.Remove cannot remove it on Windows while that handle remains open; the cleanup error is currently ignored.

To Reproduce

  1. Start from a clean checkout on Windows.

  2. Run:

    go test ./pkg/route -run '^TestRouteStaticFile$' -count=1
    git status --short
  3. The test passes, but git status reports a numeric file such as:

    ?? pkg/route/3621247847

The leftover file contains Hertz Web Framework, the fixture body written by the test.

Expected behavior

A successful test run should leave the checkout clean and should not leak temporary files.

Screenshots

Not applicable.

Hertz version:

main at 3415de4ca25f550996dab49d62839ebc6165d6b9 (v0.10.6)

Environment:

go version go1.26.3 windows/amd64
GOOS=windows
GOARCH=amd64
CGO_ENABLED=0

Additional context

This reproduces consistently in both the focused test and the full go test ./... run. A small test-only fix can use an existing tracked text fixture instead of creating a temporary file in the package directory.