MCPcopy Index your code
hub / github.com/docker/cli / TestAttributesFromError

Function TestAttributesFromError

cli/command/telemetry_utils_test.go:148–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

146}
147
148func TestAttributesFromError(t *testing.T) {
149 t.Parallel()
150
151 for _, tc := range []struct {
152 testName string
153 err error
154 expected []attribute.KeyValue
155 }{
156 {
157 testName: "no error",
158 err: nil,
159 expected: []attribute.KeyValue{
160 attribute.Int("command.status.code", 0),
161 },
162 },
163 {
164 testName: "non-0 exit code",
165 err: statusError{StatusCode: 127},
166 expected: []attribute.KeyValue{
167 attribute.String("command.error.type", "generic"),
168 attribute.Int("command.status.code", 127),
169 },
170 },
171 {
172 testName: "canceled",
173 err: context.Canceled,
174 expected: []attribute.KeyValue{
175 attribute.String("command.error.type", "canceled"),
176 attribute.Int("command.status.code", 1),
177 },
178 },
179 } {
180 t.Run(tc.testName, func(t *testing.T) {
181 t.Parallel()
182 actual := attributesFromError(tc.err)
183 assert.Check(t, is.DeepEqual(actual, tc.expected, cmpopts.EquateComparable(attribute.Value{})))
184 })
185 }
186}

Callers

nothing calls this directly

Calls 2

attributesFromErrorFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…