-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_test.go
More file actions
69 lines (60 loc) · 1.91 KB
/
Copy pathmock_test.go
File metadata and controls
69 lines (60 loc) · 1.91 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package loglayer_test
import (
"errors"
"testing"
"go.loglayer.dev/v2"
)
func TestNewMockReturnsUsableLogger(t *testing.T) {
log := loglayer.NewMock()
if log == nil {
t.Fatal("NewMock returned nil")
}
// All level methods should be safe to call.
log.Debug("debug")
log.Info("info")
log.Warn("warn")
log.Error("error")
log.Fatal("fatal") // does not exit
}
func TestNewMockBuilderChain(t *testing.T) {
log := loglayer.NewMock()
log.WithMetadata(map[string]any{"k": "v"}).
WithError(errors.New("boom")).
Error("failed")
// Reaching this line without panic is success.
}
func TestNewMockHonorsContextAndLevels(t *testing.T) {
log := loglayer.NewMock()
log = log.WithFields(loglayer.Fields{"requestId": "abc"})
if log.GetFields()["requestId"] != "abc" {
t.Errorf("mock should still track context: %v", log.GetFields())
}
log.SetLevel(loglayer.LogLevelWarn)
if log.IsLevelEnabled(loglayer.LogLevelInfo) {
t.Error("mock should still respect SetLevel: info should be disabled at warn threshold")
}
}
func TestNewMockChildIsIndependent(t *testing.T) {
log := loglayer.NewMock()
log = log.WithFields(loglayer.Fields{"shared": "v"})
child := log.Child()
child = child.WithFields(loglayer.Fields{"only_child": "x"})
if log.GetFields()["only_child"] != nil {
t.Errorf("parent should not see child context: %v", log.GetFields())
}
if child.GetFields()["shared"] != "v" {
t.Errorf("child should inherit parent context: %v", child.GetFields())
}
}
func TestNewMockGetLoggerInstanceIsNil(t *testing.T) {
log := loglayer.NewMock()
if got := log.GetLoggerInstance("mock"); got != nil {
t.Errorf("mock transport should expose nil underlying logger, got %T", got)
}
}
func TestNewMockMetadataOnlyAndErrorOnly(t *testing.T) {
log := loglayer.NewMock()
log.MetadataOnly(map[string]any{"k": "v"})
log.ErrorOnly(errors.New("only"))
// No assertions — just verify these are no-op-safe with the discard transport.
}