MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestRecordError

Function TestRecordError

pkg/otelx/otelx_test.go:107–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

105}
106
107func TestRecordError(t *testing.T) {
108 tests := []struct {
109 name string
110 err error
111 wantStatus codes.Code
112 }{
113 {
114 name: "nil error does not set error status",
115 err: nil,
116 wantStatus: codes.Unset,
117 },
118 {
119 name: "non-nil error sets error status",
120 err: errors.New("something failed"),
121 wantStatus: codes.Error,
122 },
123 }
124
125 for _, tc := range tests {
126 t.Run(tc.name, func(t *testing.T) {
127 exporter := setupTestProvider(t)
128
129 tracer := Tracer("test-svc", "biz/test")
130 _, span := Start(context.Background(), tracer, "op")
131 RecordError(span, tc.err)
132 span.End()
133
134 spans := exporter.GetSpans()
135 require.Len(t, spans, 1)
136 assert.Equal(t, tc.wantStatus, spans[0].Status.Code)
137 })
138 }
139}

Callers

nothing calls this directly

Calls 5

setupTestProviderFunction · 0.85
TracerFunction · 0.85
StartFunction · 0.85
RecordErrorFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected