@@ -33,9 +33,9 @@ func generatLoggerGroup() *logger.Logger {
3333 Logger ())
3434}
3535
36- /**
37- *
38- **/
36+ /************************************
37+ * Mockapplogger for testing purposes *
38+ ************************************ /
3939
4040// mockSublogger minimally implements abstraction.Logger for testing error propagation.
4141type mockSublogger struct {
@@ -63,8 +63,29 @@ type mockRecord struct {
6363
6464func (r * mockRecord ) Name () abstraction.LoggerName { return r .n }
6565
66+ // chdirTemp changes the current working directory to a temporary directory for the duration of the test.
67+ func chdirTemp (t * testing.T ) string {
68+ t .Helper ()
69+ tmp := t .TempDir ()
70+ old , err := os .Getwd ()
71+ if err != nil {
72+ t .Fatal (err )
73+ }
74+ if err := os .Chdir (tmp ); err != nil {
75+ t .Fatal (err )
76+ }
77+ t .Cleanup (func () { _ = os .Chdir (old ) })
78+ return tmp
79+ }
80+
81+ /************************************
82+ * Test functions for logger group *
83+ ************************************/
84+
6685func TestCreateLoggerGroup (t * testing.T ) {
6786
87+ _ = chdirTemp (t ) // Change to a temporary directory
88+
6889 // logger handler
6990 var loggerHandler * logger.Logger
7091
@@ -89,6 +110,9 @@ func TestCreateLoggerGroup(t *testing.T) {
89110}
90111
91112func TestLoggerGroup_Errors (t * testing.T ) {
113+
114+ _ = chdirTemp (t ) // Change to a temporary directory
115+
92116 // Logger with empty map → PushRecord should return error (no sublogger)
93117 lEmpty := logger .NewLogger (map [abstraction.LoggerName ]abstraction.Logger {}, zerolog .New (os .Stdout ))
94118 err := lEmpty .PushRecord (& mockRecord {n : abstraction .LoggerName ("missing" )})
@@ -109,6 +133,8 @@ func TestLoggerGroup_Errors(t *testing.T) {
109133
110134func TestStartAndStopLoggerGroup (t * testing.T ) {
111135
136+ _ = chdirTemp (t ) // Change to a temporary directory
137+
112138 // logger handler
113139 loggerHandler := generatLoggerGroup ()
114140
0 commit comments