(t *testing.T)
| 33 | ) |
| 34 | |
| 35 | func 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 + ` |
| 50 | Error types: (1) *errors.errorString` |
| 51 | tt.CheckEqual(string(redact.Sprintf("%+v", err)), expected) |
| 52 | |
| 53 | expected = sm + `hello` + em + ` |
| 54 | (1) |
| 55 | Wraps: (2) ` + sm + `hello` + em + ` |
| 56 | Error 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 | |
| 80 | type fmtWrap struct { |
| 81 | err error |
nothing calls this directly
no test coverage detected
searching dependent graphs…