@@ -9,6 +9,13 @@ import (
99 "github.com/stretchr/testify/assert"
1010)
1111
12+ const (
13+ logPrefixDebug = "[DEBUG]"
14+ logPrefixInfo = "[INFO]"
15+ logPrefixWarn = "[WARN]"
16+ logPrefixError = "[ERROR]"
17+ )
18+
1219func TestDefaultLoggerDebugf (t * testing.T ) {
1320 tests := []struct {
1421 name string
@@ -21,21 +28,21 @@ func TestDefaultLoggerDebugf(t *testing.T) {
2128 name : "simple debug message" ,
2229 format : "test message" ,
2330 args : nil ,
24- expectedPrefix : "[DEBUG]" ,
31+ expectedPrefix : logPrefixDebug ,
2532 expectedMsg : "test message" ,
2633 },
2734 {
2835 name : "debug message with formatting" ,
2936 format : "user %s logged in with ID %d" ,
3037 args : []any {"alice" , 42 },
31- expectedPrefix : "[DEBUG]" ,
38+ expectedPrefix : logPrefixDebug ,
3239 expectedMsg : "user alice logged in with ID 42" ,
3340 },
3441 {
3542 name : "debug message with multiple args" ,
3643 format : "processing %d items for %s in %v seconds" ,
3744 args : []any {100 , "test" , 3.14 },
38- expectedPrefix : "[DEBUG]" ,
45+ expectedPrefix : logPrefixDebug ,
3946 expectedMsg : "processing 100 items for test in 3.14 seconds" ,
4047 },
4148 }
@@ -70,21 +77,21 @@ func TestDefaultLoggerInfof(t *testing.T) {
7077 name : "simple info message" ,
7178 format : "server started" ,
7279 args : nil ,
73- expectedPrefix : "[INFO]" ,
80+ expectedPrefix : logPrefixInfo ,
7481 expectedMsg : "server started" ,
7582 },
7683 {
7784 name : "info message with formatting" ,
7885 format : "listening on port %d" ,
7986 args : []any {8080 },
80- expectedPrefix : "[INFO]" ,
87+ expectedPrefix : logPrefixInfo ,
8188 expectedMsg : "listening on port 8080" ,
8289 },
8390 {
8491 name : "info message with string formatting" ,
8592 format : "connected to %s at %s" ,
8693 args : []any {"database" , "localhost:5432" },
87- expectedPrefix : "[INFO]" ,
94+ expectedPrefix : logPrefixInfo ,
8895 expectedMsg : "connected to database at localhost:5432" ,
8996 },
9097 }
@@ -118,21 +125,21 @@ func TestDefaultLoggerWarnf(t *testing.T) {
118125 name : "simple warning message" ,
119126 format : "deprecated API used" ,
120127 args : nil ,
121- expectedPrefix : "[WARN]" ,
128+ expectedPrefix : logPrefixWarn ,
122129 expectedMsg : "deprecated API used" ,
123130 },
124131 {
125132 name : "warning with error details" ,
126133 format : "retry attempt %d failed: %s" ,
127134 args : []any {3 , "connection timeout" },
128- expectedPrefix : "[WARN]" ,
135+ expectedPrefix : logPrefixWarn ,
129136 expectedMsg : "retry attempt 3 failed: connection timeout" ,
130137 },
131138 {
132139 name : "warning with multiple values" ,
133140 format : "cache miss for key %s, loading from %s" ,
134141 args : []any {"user:123" , "database" },
135- expectedPrefix : "[WARN]" ,
142+ expectedPrefix : logPrefixWarn ,
136143 expectedMsg : "cache miss for key user:123, loading from database" ,
137144 },
138145 }
@@ -166,21 +173,21 @@ func TestDefaultLoggerErrorf(t *testing.T) {
166173 name : "simple error message" ,
167174 format : "connection failed" ,
168175 args : nil ,
169- expectedPrefix : "[ERROR]" ,
176+ expectedPrefix : logPrefixError ,
170177 expectedMsg : "connection failed" ,
171178 },
172179 {
173180 name : "error with details" ,
174181 format : "failed to process request: %s" ,
175182 args : []any {"invalid input" },
176- expectedPrefix : "[ERROR]" ,
183+ expectedPrefix : logPrefixError ,
177184 expectedMsg : "failed to process request: invalid input" ,
178185 },
179186 {
180187 name : "error with multiple fields" ,
181188 format : "database error on table %s: %v (code: %d)" ,
182189 args : []any {"users" , "constraint violation" , 1062 },
183- expectedPrefix : "[ERROR]" ,
190+ expectedPrefix : logPrefixError ,
184191 expectedMsg : "database error on table users: constraint violation (code: 1062)" ,
185192 },
186193 }
@@ -223,10 +230,10 @@ func TestDefaultLoggerAllLevels(t *testing.T) {
223230 assert .Len (t , lines , 4 )
224231
225232 // Verify each level appears once
226- assert .Contains (t , output , "[DEBUG]" )
227- assert .Contains (t , output , "[INFO]" )
228- assert .Contains (t , output , "[WARN]" )
229- assert .Contains (t , output , "[ERROR]" )
233+ assert .Contains (t , output , logPrefixDebug )
234+ assert .Contains (t , output , logPrefixInfo )
235+ assert .Contains (t , output , logPrefixWarn )
236+ assert .Contains (t , output , logPrefixError )
230237
231238 // Verify messages are correct
232239 assert .Contains (t , output , "debug message" )
0 commit comments