cloudwego / cloudwego/hertz

TestRouteStaticFile leaves an untracked temporary file on Windows

Open Beginner friendly
#1,540 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
7.4k
Forks
643
Avg merge
14h 5m
Merged PRs (30d)
2

Description

**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:

```text
go test ./pkg/route -run '^TestRouteStaticFile$' -count=1
git status --short
```

3. The test passes, but `git status` reports a numeric file such as:

```text
?? 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:**

```text
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.

Contributor guide

Open the contributing guide

Research direction

Inspect TestRouteStaticFile in pkg/route and first reproduce the leak with go test ./pkg/route -run '^TestRouteStaticFile$' -count=1 on Windows. Check the existing tracked text fixtures and the test's temporary-file cleanup. Done means the test still passes and git status --short reports no untracked fixture files.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.