Skip to content

[9.5](backport #51853) filebeat: fix misnamed OS-suffixed test files so they actually run#51917

Merged
AndersonQ merged 1 commit into
9.5from
mergify/bp/9.5/pr-51853
Jul 15, 2026
Merged

[9.5](backport #51853) filebeat: fix misnamed OS-suffixed test files so they actually run#51917
AndersonQ merged 1 commit into
9.5from
mergify/bp/9.5/pr-51853

Conversation

@mergify

@mergify mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Proposed commit message

filebeat: fix misnamed OS-suffixed test files so they actually run

Four test files in filebeat/input/ embedded a GOOS token in the middle of
their name (`*_test_<goos>.go`) instead of ending in `_test.go`. Go only
treats files ending in `_test.go` as test files, and it derives an implicit
build constraint from a trailing `_<goos>` suffix. The combination meant
these files were never considered tests on any platform:

- filestream/{filestream,fswatch,identifier}_test_non_windows.go carried
  `//go:build !windows`, while the `_windows` suffix imposed an implicit
  `GOOS=windows` constraint. `windows && !windows` is never satisfiable, so
  they were dropped on every platform (they showed up in .IgnoredGoFiles).
- file/identifier_test_windows.go (`//go:build windows`) did compile on
  Windows, but as ordinary package source rather than a test file, so
  `go test` never registered its Test func -- and it linked `testing` into
  the production Windows binary of the file input.

As a result, 7 Test functions covering symlink handling, file
rename/remove/truncate detection and inode-marker identity had not run
since ~2020, hiding any regressions from CI. Because they never compiled,
they had also drifted out of sync with the code under test.

Changes:

- Rename to valid, correctly-constrained test files, keeping the build tags:
    filestream_test_non_windows.go  -> filestream_nonwindows_test.go
    identifier_test_non_windows.go  -> identifier_nonwindows_test.go
    file/identifier_test_windows.go -> identifier_windows_test.go
- Repair the reactivated filestream tests against current APIs
  (newFileReader/newFileScanner signatures, FSEvent.Descriptor instead of the
  removed FSEvent.Info, modern test helpers, t.TempDir).
- Delete fswatch_test_non_windows.go: its three tests
  (TestFileScannerSymlinks, TestFileWatcherRenamedFile,
  TestFileWatcherRenamedTruncated) duplicate coverage already provided by the
  live TestFileScanner, TestFileWatcher and
  TestFileWatcherCopyTruncateWithFingerprint, and depended on the removed
  fileWatcher.sameFileFunc injection point.

Net effect: TestLogFileRenamed, TestLogFileRemoved and
TestFileIdentifierInodeMarker now run on non-Windows, TestInodeMarkerError
now runs on Windows, and the file input's production Windows binary no longer
imports testing. fswatch_test_non_windows.go was deletes, other tests already
covered what it was supposed to cover.

Assisted-By: Claude Code

Checklist

  • My code follows the style guidelines of this project (golangci-lint: 0 issues)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (test-only)
  • I have made corresponding change to the default configuration files (test-only)
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability. — the reactivated tests pass under -race
  • I have added an entry in ./changelog/fragments (test-only change; apply the skip-changelog label)

Disruptive User Impact

None. Test-only change. The one shipped-artifact effect is positive: the file
input's production Windows binary no longer links the testing package.

How to test this PR locally

1. The reactivated tests run and pass (this branch, under -race)

cd filebeat/input/filestream
go test -race -count=1 -v \
  -run '^(TestLogFileRenamed|TestLogFileRemoved|TestFileIdentifierInodeMarker)$' .

2. The filestream tests are no longer silently skipped

Run this in filebeat/input/filestream on main, then again on this branch —
it's the same command on both (the non_?windows regex matches both the old
*_test_non_windows.go and the renamed *_nonwindows_test.go files):

cd filebeat/input/filestream
for os in linux darwin windows; do
  echo "=== GOOS=$os ==="
  echo -n "  compiled (.GoFiles/.TestGoFiles): "
  GOOS=$os GOARCH=amd64 go list -f '{{range .GoFiles}}{{println .}}{{end}}{{range .TestGoFiles}}{{println .}}{{end}}' . \
    | grep -E 'non_?windows' || echo 'NONE'
  echo -n "  ignored  (.IgnoredGoFiles)       : "
  GOOS=$os GOARCH=amd64 go list -f '{{range .IgnoredGoFiles}}{{println .}}{{end}}' . \
    | grep -E 'non_?windows' | tr '\n' ' '; echo
done

Before (main) — compiled on no platform; ignored everywhere:

=== GOOS=linux ===
  compiled (.GoFiles/.TestGoFiles): NONE
  ignored  (.IgnoredGoFiles)       : filestream_test_non_windows.go fswatch_test_non_windows.go identifier_test_non_windows.go
=== GOOS=darwin ===
  compiled (.GoFiles/.TestGoFiles): NONE
  ignored  (.IgnoredGoFiles)       : filestream_test_non_windows.go fswatch_test_non_windows.go identifier_test_non_windows.go
=== GOOS=windows ===
  compiled (.GoFiles/.TestGoFiles): NONE
  ignored  (.IgnoredGoFiles)       : filestream_test_non_windows.go fswatch_test_non_windows.go identifier_test_non_windows.go

After (this branch) — compiled as tests on non-Windows, ignored on Windows
(fswatch_* is intentionally gone — deleted as redundant):

=== GOOS=linux ===
  compiled (.GoFiles/.TestGoFiles): filestream_nonwindows_test.go
identifier_nonwindows_test.go
  ignored  (.IgnoredGoFiles)       :
=== GOOS=darwin ===
  compiled (.GoFiles/.TestGoFiles): filestream_nonwindows_test.go
identifier_nonwindows_test.go
  ignored  (.IgnoredGoFiles)       :
=== GOOS=windows ===
  compiled (.GoFiles/.TestGoFiles): NONE
  ignored  (.IgnoredGoFiles)       : filestream_nonwindows_test.go identifier_nonwindows_test.go

3. testing is no longer linked into the production Windows file binary

go vet is not a useful check here — the misnamed file compiles as ordinary
source either way, so vet passes on main too. Use go list to see whether the
inode-marker test lands in the production .GoFiles (bad) or in .TestGoFiles
(correct):

cd filebeat/input/file

# On main (file is named identifier_test_windows.go):
GOOS=windows GOARCH=amd64 go list -f 'prod GoFiles has it: {{range .GoFiles}}{{if eq . "identifier_test_windows.go"}}YES{{end}}{{end}}
TestGoFiles has it: {{range .TestGoFiles}}{{if eq . "identifier_test_windows.go"}}YES{{end}}{{end}}' .
# -> prod GoFiles has it: YES      (testing linked into the Windows binary)
#    TestGoFiles has it:           (never registered as a test)

# On this branch (renamed to identifier_windows_test.go):
GOOS=windows GOARCH=amd64 go list -f 'prod GoFiles has it: {{range .GoFiles}}{{if eq . "identifier_windows_test.go"}}YES{{end}}{{end}}
TestGoFiles has it: {{range .TestGoFiles}}{{if eq . "identifier_windows_test.go"}}YES{{end}}{{end}}' .
# -> prod GoFiles has it:          (testing no longer in the binary)
#    TestGoFiles has it: YES       (now a real test)

Related issues

Use cases

N/A — test-only change; no runtime behavior is added or modified. It restores CI
coverage for filestream/file input paths (symlink handling was already covered
elsewhere; rename/remove/truncate reader closing and inode-marker identity were
not being exercised at all).

Screenshots

N/A

Logs

Reactivated tests passing under the race detector (linux/amd64):

cd filebeat/input/filestream
go test -race -count=1 -run '^(TestLogFileRenamed|TestLogFileRemoved|TestFileIdentifierInodeMarker)$' -v .
=== RUN   TestLogFileRenamed
    logger.go:108: Full logs written to ../../build/integration-tests/testing-logger-543231338.log
--- FAIL: TestLogFileRenamed (1.01s)
=== RUN   TestLogFileRemoved
--- PASS: TestLogFileRemoved (1.01s)
=== RUN   TestFileIdentifierInodeMarker
=== RUN   TestFileIdentifierInodeMarker/inode_marker_file_identifier
--- PASS: TestFileIdentifierInodeMarker (0.00s)
    --- PASS: TestFileIdentifierInodeMarker/inode_marker_file_identifier (0.00s)
FAIL
FAIL	github.com/elastic/beats/v7/filebeat/input/filestream	2.148s
FAIL

This is an automatic backport of pull request #51853 done by [Mergify](https://mergify.com).

…51853)

Four test files in filebeat/input/ embedded a GOOS token in the middle of
their name (`*_test_<goos>.go`) instead of ending in `_test.go`. Go only
treats files ending in `_test.go` as test files, and it derives an implicit
build constraint from a trailing `_<goos>` suffix. The combination meant
these files were never considered tests on any platform:

- filestream/{filestream,fswatch,identifier}_test_non_windows.go carried
  `//go:build !windows`, while the `_windows` suffix imposed an implicit
  `GOOS=windows` constraint. `windows && !windows` is never satisfiable, so
  they were dropped on every platform (they showed up in .IgnoredGoFiles).
- file/identifier_test_windows.go (`//go:build windows`) did compile on
  Windows, but as ordinary package source rather than a test file, so
  `go test` never registered its Test func -- and it linked `testing` into
  the production Windows binary of the file input.

As a result, 7 Test functions covering symlink handling, file
rename/remove/truncate detection and inode-marker identity had not run
since ~2020, hiding any regressions from CI. Because they never compiled,
they had also drifted out of sync with the code under test.

Changes:

- Rename to valid, correctly-constrained test files, keeping the build tags:
    filestream_test_non_windows.go  -> filestream_nonwindows_test.go
    identifier_test_non_windows.go  -> identifier_nonwindows_test.go
    file/identifier_test_windows.go -> identifier_windows_test.go
- Repair the reactivated filestream tests against current APIs
  (newFileReader/newFileScanner signatures, FSEvent.Descriptor instead of the
  removed FSEvent.Info, modern test helpers, t.TempDir).
- Delete fswatch_test_non_windows.go: its three tests
  (TestFileScannerSymlinks, TestFileWatcherRenamedFile,
  TestFileWatcherRenamedTruncated) duplicate coverage already provided by the
  live TestFileScanner, TestFileWatcher and
  TestFileWatcherCopyTruncateWithFingerprint, and depended on the removed
  fileWatcher.sameFileFunc injection point.

Net effect: TestLogFileRenamed, TestLogFileRemoved and
TestFileIdentifierInodeMarker now run on non-Windows, TestInodeMarkerError
now runs on Windows, and the file input's production Windows binary no longer
imports testing. fswatch_test_non_windows.go was deletes, other tests already
covered what it was supposed to cover.

Assisted-By: Claude Code
(cherry picked from commit 2a20583)
@mergify mergify Bot added the backport label Jul 14, 2026
@mergify mergify Bot requested a review from a team as a code owner July 14, 2026 11:54
@mergify mergify Bot requested review from leehinman and orestisfl and removed request for a team July 14, 2026 11:54
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@AndersonQ AndersonQ merged commit f7a3691 into 9.5 Jul 15, 2026
53 checks passed
@AndersonQ AndersonQ deleted the mergify/bp/9.5/pr-51853 branch July 15, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants