Skip to content

Commit 7d681c7

Browse files
committed
Lint fixes.
Signed-off-by: Josh Baird <[email protected]>
1 parent f2e504a commit 7d681c7

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

cmd/fluent-manager/main_test.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import (
88
"github.com/joho/godotenv"
99
)
1010

11+
const (
12+
defaultContainerLogPath = "/var/log/containers"
13+
)
14+
1115
// TestContainerLogPathResolution tests the container log path resolution logic
1216
// that will be added to main.go
1317
func TestContainerLogPathResolution(t *testing.T) {
1418
tests := []struct {
15-
name string
16-
envVar string
17-
fileContent string
18-
expectedPath string
19-
setupFile bool
19+
name string
20+
envVar string
21+
fileContent string
22+
expectedPath string
23+
setupFile bool
2024
}{
2125
{
2226
name: "prefer environment variable over file",
@@ -43,7 +47,7 @@ func TestContainerLogPathResolution(t *testing.T) {
4347
name: "use default when neither env var nor file present",
4448
envVar: "",
4549
fileContent: "",
46-
expectedPath: "/var/log/containers",
50+
expectedPath: defaultContainerLogPath,
4751
setupFile: false,
4852
},
4953
{
@@ -57,7 +61,7 @@ func TestContainerLogPathResolution(t *testing.T) {
5761
name: "handle empty env var (should fallback)",
5862
envVar: "",
5963
fileContent: "CONTAINER_ROOT_DIR=/var/log",
60-
expectedPath: "/var/log/containers",
64+
expectedPath: defaultContainerLogPath,
6165
setupFile: true,
6266
},
6367
}
@@ -70,10 +74,18 @@ func TestContainerLogPathResolution(t *testing.T) {
7074

7175
// Setup environment variable
7276
if tt.envVar != "" {
73-
os.Setenv("CONTAINER_LOG_PATH", tt.envVar)
74-
defer os.Unsetenv("CONTAINER_LOG_PATH")
77+
if err := os.Setenv("CONTAINER_LOG_PATH", tt.envVar); err != nil {
78+
t.Fatalf("failed to set env var: %v", err)
79+
}
80+
defer func() {
81+
if err := os.Unsetenv("CONTAINER_LOG_PATH"); err != nil {
82+
t.Errorf("failed to unset env var: %v", err)
83+
}
84+
}()
7585
} else {
76-
os.Unsetenv("CONTAINER_LOG_PATH")
86+
if err := os.Unsetenv("CONTAINER_LOG_PATH"); err != nil {
87+
t.Fatalf("failed to unset env var: %v", err)
88+
}
7789
}
7890

7991
// Setup file if needed
@@ -99,7 +111,7 @@ func TestContainerLogPathResolution(t *testing.T) {
99111

100112
// Final fallback to safe default for containerd/CRI-O
101113
if logPath == "" {
102-
logPath = "/var/log/containers"
114+
logPath = defaultContainerLogPath
103115
}
104116

105117
// Verify result
@@ -123,8 +135,14 @@ func TestContainerLogPathEnvVarPrecedence(t *testing.T) {
123135

124136
// Set env var with different path
125137
envPath := "/env/var/wins"
126-
os.Setenv("CONTAINER_LOG_PATH", envPath)
127-
defer os.Unsetenv("CONTAINER_LOG_PATH")
138+
if err := os.Setenv("CONTAINER_LOG_PATH", envPath); err != nil {
139+
t.Fatalf("failed to set env var: %v", err)
140+
}
141+
defer func() {
142+
if err := os.Unsetenv("CONTAINER_LOG_PATH"); err != nil {
143+
t.Errorf("failed to unset env var: %v", err)
144+
}
145+
}()
128146

129147
// Execute resolution logic
130148
var logPath string
@@ -134,7 +152,7 @@ func TestContainerLogPathEnvVarPrecedence(t *testing.T) {
134152
logPath = envs["CONTAINER_ROOT_DIR"] + "/containers"
135153
}
136154
if logPath == "" {
137-
logPath = "/var/log/containers"
155+
logPath = defaultContainerLogPath
138156
}
139157

140158
// Env var should win
@@ -149,7 +167,9 @@ func TestContainerLogPathFilePathsAppendContainers(t *testing.T) {
149167
testFile := filepath.Join(tmpDir, "fluent-bit.env")
150168

151169
// Unset env var
152-
os.Unsetenv("CONTAINER_LOG_PATH")
170+
if err := os.Unsetenv("CONTAINER_LOG_PATH"); err != nil {
171+
t.Fatalf("failed to unset env var: %v", err)
172+
}
153173

154174
tests := []struct {
155175
rootDir string
@@ -181,4 +201,3 @@ func TestContainerLogPathFilePathsAppendContainers(t *testing.T) {
181201
})
182202
}
183203
}
184-

0 commit comments

Comments
 (0)