MCPcopy
hub / github.com/kopia/kopia / TestError

Function TestError

internal/contentlog/logparam/logparam_test.go:397–459  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

395}
396
397func TestError(t *testing.T) {
398 err1 := errors.Errorf("test error")
399 err2 := errors.Errorf("another error")
400
401 var nilErr error
402
403 tests := []struct {
404 name string
405 key string
406 value error
407 expected map[string]any
408 }{
409 {
410 name: "simple error",
411 key: "err",
412 value: err1,
413 expected: map[string]any{
414 "err": "test error",
415 },
416 },
417 {
418 name: "another error",
419 key: "error",
420 value: err2,
421 expected: map[string]any{
422 "error": "another error",
423 },
424 },
425 {
426 name: "nil error",
427 key: "nil",
428 value: nilErr,
429 expected: map[string]any{
430 "nil": nil,
431 },
432 },
433 }
434
435 for _, tt := range tests {
436 t.Run(tt.name, func(t *testing.T) {
437 // Test memory allocations
438 allocs := testing.AllocsPerRun(100, func() {
439 _ = Error(tt.key, tt.value)
440 })
441 require.Equal(t, float64(0), allocs, "Error() should not allocate memory")
442
443 // Test output format
444 param := Error(tt.key, tt.value)
445
446 jw := contentlog.NewJSONWriter()
447 defer jw.Release()
448
449 jw.BeginObject()
450 param.WriteValueTo(jw)
451 jw.EndObject()
452
453 var result map[string]any
454

Callers

nothing calls this directly

Calls 10

ReleaseMethod · 0.95
BeginObjectMethod · 0.95
EndObjectMethod · 0.95
GetBufferForTestingMethod · 0.95
NewJSONWriterFunction · 0.92
ErrorFunction · 0.85
ErrorfMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
WriteValueToMethod · 0.65

Tested by

no test coverage detected