fix: resolve comments
This commit is contained in:
@@ -14,8 +14,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testLogFilePath = "./test_logs/test.log"
|
|
||||||
|
|
||||||
type ctxKey any
|
type ctxKey any
|
||||||
|
|
||||||
var requestID ctxKey = "requestID"
|
var requestID ctxKey = "requestID"
|
||||||
@@ -23,11 +21,10 @@ var userID ctxKey = "userID"
|
|||||||
|
|
||||||
func setupLogger(t *testing.T, l level) string {
|
func setupLogger(t *testing.T, l level) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
dir := filepath.Dir(testLogFilePath)
|
|
||||||
err := os.MkdirAll(dir, os.ModePerm)
|
// Create a temporary directory for logs.
|
||||||
if err != nil {
|
tempDir := t.TempDir()
|
||||||
t.Fatalf("failed to create test log directory: %v", err)
|
testLogFilePath := filepath.Join(tempDir, "test.log")
|
||||||
}
|
|
||||||
|
|
||||||
config := Config{
|
config := Config{
|
||||||
Level: l,
|
Level: l,
|
||||||
@@ -45,10 +42,13 @@ func setupLogger(t *testing.T, l level) string {
|
|||||||
},
|
},
|
||||||
ContextKeys: []string{"userID", "requestID"},
|
ContextKeys: []string{"userID", "requestID"},
|
||||||
}
|
}
|
||||||
err = InitLogger(config)
|
|
||||||
|
// Initialize logger with the given config
|
||||||
|
err := InitLogger(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to initialize logger: %v", err)
|
t.Fatalf("failed to initialize logger: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return testLogFilePath
|
return testLogFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +72,7 @@ func parseLogLine(t *testing.T, line string) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDebug(t *testing.T) {
|
func TestDebug(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
logPath := setupLogger(t, DebugLevel)
|
logPath := setupLogger(t, DebugLevel)
|
||||||
ctx := context.WithValue(context.Background(), userID, "12345")
|
ctx := context.WithValue(context.Background(), userID, "12345")
|
||||||
Debug(ctx, "Debug message")
|
Debug(ctx, "Debug message")
|
||||||
|
|||||||
Reference in New Issue
Block a user