MCPcopy Create free account
hub / github.com/cockroachdb/errors / TestRedact

Function TestRedact

safedetails/redact_test.go:31–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestRedact(t *testing.T) {
32 errSentinel := (error)(struct{ error }{})
33
34 // rm is what's left over after redaction.
35 rm := string(redact.RedactableBytes(redact.RedactedMarker()).StripMarkers())
36
37 testData := []struct {
38 obj interface{}
39 expected string
40 }{
41 // Redacting non-error values.
42
43 {123, rm},
44 {"secret", rm},
45
46 // Redacting SafeMessagers.
47
48 {mySafer{}, `hello`},
49
50 {safedetails.Safe(123), `123`},
51
52 {mySafeError{}, `hello`},
53
54 {&werrFmt{mySafeError{}, "unseen"}, rm + `: hello`},
55
56 // Redacting errors.
57
58 // Unspecial cases, get redacted.
59 {errors.New("secret"), rm},
60
61 // Special cases, unredacted.
62 {os.ErrInvalid, `invalid argument`},
63 {os.ErrPermission, `permission denied`},
64 {os.ErrExist, `file already exists`},
65 {os.ErrNotExist, `file does not exist`},
66 {os.ErrClosed, `file already closed`},
67 {os.ErrNoDeadline, `file type does not support deadline`},
68
69 {context.Canceled, `context canceled`},
70 {context.DeadlineExceeded, `context deadline exceeded`},
71
72 {makeTypeAssertionErr(), `interface conversion: interface {} is nil, not int`},
73
74 {errSentinel, // explodes if Error() called
75 `%!v(PANIC=SafeFormatter method: runtime error: invalid memory address or nil pointer dereference)`},
76
77 {&werrFmt{&werrFmt{os.ErrClosed, "unseen"}, "unsung"},
78 rm + `: ` + rm + `: file already closed`},
79
80 // Special cases, get partly redacted.
81
82 {os.NewSyscallError("rename", os.ErrNotExist),
83 `rename: file does not exist`},
84
85 {&os.PathError{Op: "rename", Path: "secret", Err: os.ErrNotExist},
86 `rename ` + rm + `: file does not exist`},
87
88 {&os.LinkError{

Callers

nothing calls this directly

Calls 4

CheckStringEqualMethod · 0.95
SafeFunction · 0.92
RedactFunction · 0.92
makeTypeAssertionErrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…