MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestFormatViaRedact

Function TestFormatViaRedact

fmttests/format_error_test.go:35–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33)
34
35func TestFormatViaRedact(t *testing.T) {
36 tt := testutils.T{t}
37
38 sm := string(redact.StartMarker())
39 em := string(redact.EndMarker())
40
41 var nilErr error
42 err := errutil.Newf("hello %s %v", "world", nilErr)
43
44 tt.CheckEqual(string(redact.Sprintf("%v", err)), `hello `+sm+`world`+em+` <nil>`)
45 tt.CheckEqual(string(redact.Sprintf("%v", errbase.Formattable(err))), `hello `+sm+`world`+em+` <nil>`)
46
47 err = goErr.New("hello")
48 expected := sm + `hello` + em + `
49(1) ` + sm + `hello` + em + `
50Error types: (1) *errors.errorString`
51 tt.CheckEqual(string(redact.Sprintf("%+v", err)), expected)
52
53 expected = sm + `hello` + em + `
54(1)
55Wraps: (2) ` + sm + `hello` + em + `
56Error types: (1) *errbase.errorFormatter (2) *errors.errorString`
57 tt.CheckEqual(string(redact.Sprintf("%+v", errbase.Formattable(err))), expected)
58
59 // Regression test.
60 f := &fmtWrap{err}
61 tt.CheckEqual(string(redact.Sprintf("%v", f)), sm+`hello`+em)
62 expected = sm + `hello` + em + `
63` + sm + `(1) hello` + em + `
64` + sm + `Error types: (1) *errors.errorString` + em
65 tt.CheckEqual(string(redact.Sprintf("%+v", f)), expected)
66
67 // Regression test 2.
68 f2 := &fmter{}
69 tt.CheckEqual(string(redact.Sprintf("%v", f2)), sm+`hello`+em)
70 tt.CheckEqual(string(redact.Sprintf("%+v", f2)), sm+`hello`+em)
71
72 // Another regression test.
73 // https://github.com/cockroachdb/redact/issues/12
74 var buf redact.StringBuilder
75 buf.Printf("safe %v", "unsafe")
76 e := errutil.Newf("%v", buf)
77 tt.CheckEqual(string(redact.Sprint(e)), `safe `+sm+`unsafe`+em)
78}
79
80type fmtWrap struct {
81 err error

Callers

nothing calls this directly

Calls 4

CheckEqualMethod · 0.95
NewfFunction · 0.92
FormattableFunction · 0.92
PrintfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…