Skip to content

Commit 6bfbe86

Browse files
authored
x-pack/filebeat/input/internal/httplog: fix reserved-name Windows tests (#49028)
Remove TestMkdirAllReservedNames, which is redundant and fails on Windows 11/Server 2025 where reserved device names are no longer restricted. Update TestEvalSymlinksReservedNames to probe OS behavior by attempting os.MkdirAll with the reserved name before testing EvalSymlinks. If directory creation succeeds the OS allows reserved names and the subtest returns early; otherwise the existing assertions run unchanged.
1 parent 5b79ccc commit 6bfbe86

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

x-pack/filebeat/input/internal/httplog/roundtripper_windows_test.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io/fs"
1212
"os"
1313
"path/filepath"
14-
"slices"
1514
"testing"
1615

1716
"golang.org/x/sys/windows"
@@ -46,6 +45,9 @@ func TestEvalSymlinksReservedNames(t *testing.T) {
4645
for _, name := range []string{"CON", "PRN", "AUX"} {
4746
t.Run(name, func(t *testing.T) {
4847
p := filepath.Join(base, name, "somefile.log")
48+
if err := os.MkdirAll(filepath.Dir(p), 0o750); err == nil {
49+
return
50+
}
4951
_, err := filepath.EvalSymlinks(p)
5052
if err == nil {
5153
t.Fatal("expected error from EvalSymlinks, got nil")
@@ -60,30 +62,6 @@ func TestEvalSymlinksReservedNames(t *testing.T) {
6062
}
6163
}
6264

63-
func TestMkdirAllReservedNames(t *testing.T) {
64-
base := t.TempDir()
65-
tests := []struct {
66-
name string
67-
wantErr []error
68-
}{
69-
{"CON", []error{fs.ErrNotExist}},
70-
{"PRN", []error{windows.ERROR_DIRECTORY, windows.ERROR_PATH_NOT_FOUND}},
71-
{"AUX", []error{windows.ERROR_DIRECTORY, windows.ERROR_PATH_NOT_FOUND}},
72-
}
73-
for _, test := range tests {
74-
t.Run(test.name, func(t *testing.T) {
75-
p := filepath.Join(base, test.name, "logsdir")
76-
err := os.MkdirAll(p, 0o750)
77-
if err == nil {
78-
t.Fatal("expected error from MkdirAll, got nil")
79-
}
80-
if !slices.ContainsFunc(test.wantErr, func(e error) bool { return errors.Is(err, e) }) {
81-
t.Fatalf("MkdirAll(%q) err = %v; want in %v", p, err, test.wantErr)
82-
}
83-
})
84-
}
85-
}
86-
8765
func TestResolveSymlinksWindowsGlob(t *testing.T) {
8866
base := t.TempDir()
8967
resolved, err := filepath.EvalSymlinks(base)

0 commit comments

Comments
 (0)