@@ -7,23 +7,30 @@ import (
7
7
)
8
8
9
9
// 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
+ }
12
19
}
13
20
14
21
// TestLoggingToFile verifies that log messages are correctly logged to a file.
15
22
func TestLoggingToFile (t * testing.T ) {
16
23
// Clean up from any previous test runs
17
- cleanup ()
24
+ cleanup (t )
18
25
19
- // Initialize logger to log to file
26
+ // Initialize logger to log to file inside the output folder
20
27
Init (true , false )
21
28
22
29
// Log an info message
23
30
Info ("File logging test" )
24
31
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" )
27
34
if err != nil {
28
35
t .Fatalf ("Failed to read log file: %v" , err )
29
36
}
@@ -34,7 +41,7 @@ func TestLoggingToFile(t *testing.T) {
34
41
}
35
42
36
43
// Clean up
37
- cleanup ()
44
+ cleanup (t )
38
45
}
39
46
40
47
// Helper function to check if a byte slice contains a specific string
0 commit comments