-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger_test.go
40 lines (36 loc) · 922 Bytes
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gondola
import (
"context"
"log/slog"
"os"
"testing"
)
func TestNewLogger(t *testing.T) {
level := 1
logger := NewLogger(level)
if logger == nil {
t.Fatal("Expected logger to be created, but got nil")
}
}
func TestWithAndGetTraceID(t *testing.T) {
ctx := WithTraceID(context.Background())
tid := GetTraceID(ctx)
if tid == "" {
t.Fatal("Expected trace ID to be created, but got empty string")
}
}
func TestHandle(t *testing.T) {
handler := TraceIDHandler{slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.Level(0),
})}
ctx := context.WithValue(context.Background(), ctxTraceIDKey, "12345")
err := handler.Handle(ctx, slog.Record{Level: slog.Level(1)})
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
ctx = context.Background()
err = handler.Handle(ctx, slog.Record{Level: slog.Level(1)})
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
}