mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 14:58:33 +00:00
This solves #5679 , and also implements #5515, #5509 and lays the ground for #5516 With the introduction of Wrap, Is and As in the standard library, we've now got built-in support for wrapping. On top of that, a common pattern in the community is to define errors tailored to the context of each project while still conforming to the error and Unwrap interfaces (see Upspin, Chromium) The output now includes stack traces and additional info
35 lines
632 B
Go
35 lines
632 B
Go
package ctxerr
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type mockStack struct {
|
|
trace []string
|
|
}
|
|
|
|
func (s mockStack) List() []string {
|
|
return s.trace
|
|
}
|
|
|
|
func buildStack(depth int) stack {
|
|
if depth == 0 {
|
|
return newStack(0)
|
|
}
|
|
return buildStack(depth - 1)
|
|
}
|
|
|
|
func TestStack(t *testing.T) {
|
|
trace := buildStack(maxDepth)
|
|
lines := trace.List()
|
|
|
|
require.Equal(t, len(lines), len(trace))
|
|
|
|
re := regexp.MustCompile(`server/contexts/ctxerr\.buildStack \(stack_test.go:\d+\)$`)
|
|
for i, line := range lines {
|
|
require.Regexpf(t, re, line, "expected line %d to match %q, got %q", i, re, line)
|
|
}
|
|
}
|