-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_wrapper_test.go
More file actions
44 lines (38 loc) · 1.23 KB
/
plugin_wrapper_test.go
File metadata and controls
44 lines (38 loc) · 1.23 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
package loglayer_test
import (
"testing"
"go.loglayer.dev/v2"
"go.loglayer.dev/v2/internal/lltest"
"go.loglayer.dev/v2/transport"
)
// A wrapped DataHook plugin must NOT register for unrelated hooks. If
// it did, a chain like [wrapped(DataHook), realMetadataHook] would have
// the wrapper's pass-through OnMetadataCalled run first; with nil input
// it'd return nil and short-circuit the rest of the chain.
func TestWithErrorReporter_DoesNotInterfereWithUnrelatedHooks(t *testing.T) {
lib := &lltest.TestLoggingLibrary{}
tr := lltest.New(lltest.Config{
BaseConfig: transport.BaseConfig{ID: "test"},
Library: lib,
})
calledMeta := false
wrapped := loglayer.WithErrorReporter(
loglayer.NewDataHook("data-only", func(p loglayer.BeforeDataOutParams) loglayer.Data {
return nil
}),
func(error) {},
)
metaHook := loglayer.NewMetadataHook("real-meta", func(m any) any {
calledMeta = true
return loglayer.Metadata{"injected": true}
})
log := loglayer.New(loglayer.Config{
Transport: tr,
DisableFatalExit: true,
Plugins: []loglayer.Plugin{wrapped, metaHook},
})
log.WithMetadata(nil).Info("test")
if !calledMeta {
t.Fatal("metadata hook should run; wrapper must not register for unrelated hooks")
}
}