Skip to content

Commit 5fdf31a

Browse files
committed
fix: update logs test
1 parent 473ee96 commit 5fdf31a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

logs/logs_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@ import (
77
)
88

99
// Helper function to clean up after each test (if necessary)
10-
func cleanup() {
11-
os.Remove("argus.log") // Delete the argus.log file after tests to avoid issues in subsequent runs
10+
func cleanup(t *testing.T) {
11+
// Remove the log file if it exists
12+
os.Remove("output/argus.log")
13+
14+
// Remove the output folder if it is empty
15+
if err := os.RemoveAll("output"); err != nil {
16+
// Log an error if the folder removal fails
17+
t.Errorf("Failed to remove output folder: %v", err)
18+
}
1219
}
1320

1421
// TestLoggingToFile verifies that log messages are correctly logged to a file.
1522
func TestLoggingToFile(t *testing.T) {
1623
// Clean up from any previous test runs
17-
cleanup()
24+
cleanup(t)
1825

19-
// Initialize logger to log to file
26+
// Initialize logger to log to file inside the output folder
2027
Init(true, false)
2128

2229
// Log an info message
2330
Info("File logging test")
2431

25-
// Check if the log message is written to the argus.log file
26-
fileContent, err := os.ReadFile("argus.log")
32+
// Check if the log message is written to the output/argus.log file
33+
fileContent, err := os.ReadFile("output/argus.log")
2734
if err != nil {
2835
t.Fatalf("Failed to read log file: %v", err)
2936
}
@@ -34,7 +41,7 @@ func TestLoggingToFile(t *testing.T) {
3441
}
3542

3643
// Clean up
37-
cleanup()
44+
cleanup(t)
3845
}
3946

4047
// Helper function to check if a byte slice contains a specific string

0 commit comments

Comments
 (0)