MCPcopy Index your code
hub / github.com/coder/coder / Test_SlogSink

Function Test_SlogSink

coderd/tracing/slog_test.go:56–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func Test_SlogSink(t *testing.T) {
57 t.Parallel()
58
59 fieldsMap := map[string]interface{}{
60 "test_bool": true,
61 "test_[]bool": []bool{true, false},
62 "test_float32": float32(1.1),
63 "test_float64": float64(1.1),
64 "test_[]float64": []float64{1.1, 2.2},
65 "test_int": int(1),
66 "test_[]int": []int{1, 2},
67 "test_int8": int8(1),
68 "test_int16": int16(1),
69 "test_int32": int32(1),
70 "test_int64": int64(1),
71 "test_[]int64": []int64{1, 2},
72 "test_uint": uint(1),
73 "test_uint8": uint8(1),
74 "test_uint16": uint16(1),
75 "test_uint32": uint32(1),
76 "test_uint64": uint64(1),
77 "test_string": "test",
78 "test_[]string": []string{"test1", "test2"},
79 "test_duration": time.Second,
80 "test_time": time.Now(),
81 "test_stringer": stringer("test"),
82 "test_struct": struct {
83 Field string `json:"field"`
84 }{
85 Field: "test",
86 },
87 }
88
89 entry := slog.SinkEntry{
90 Time: time.Now(),
91 Level: slog.LevelInfo,
92 Message: "hello",
93 LoggerNames: []string{"foo", "bar"},
94 Func: "hello",
95 File: "hello.go",
96 Line: 42,
97 Fields: mapToSlogFields(fieldsMap),
98 }
99
100 t.Run("NotRecording", func(t *testing.T) {
101 t.Parallel()
102
103 sink := tracing.SlogSink{}
104 span := &slogFakeSpan{
105 isRecording: false,
106 }
107 ctx := trace.ContextWithSpan(context.Background(), span)
108
109 sink.LogEntry(ctx, entry)
110 require.Len(t, span.events, 0)
111 })
112
113 t.Run("OK", func(t *testing.T) {

Callers

nothing calls this directly

Calls 11

LogEntryMethod · 0.95
SyncMethod · 0.95
stringerTypeAlias · 0.85
mapToSlogFieldsFunction · 0.85
mapToBasicMapFunction · 0.85
attributesToMapFunction · 0.85
RunMethod · 0.65
FormatMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected