| 51 | } |
| 52 | |
| 53 | func TestLogSkip(t *testing.T) { |
| 54 | var buf bytes.Buffer |
| 55 | log.SetOutput(&buf) |
| 56 | |
| 57 | formatter := Formatter{ |
| 58 | Default: Info{500, "CH000", "Internal server error"}, |
| 59 | IsTemporary: func(Info, error) bool { return false }, |
| 60 | Errors: map[error]Info{}, |
| 61 | } |
| 62 | formatter.Log(context.Background(), errors.New("an unmapped error")) |
| 63 | |
| 64 | logStr := string(buf.Bytes()) |
| 65 | if len(logStr) == 0 { |
| 66 | t.Error("expected error to be logged") |
| 67 | } |
| 68 | if strings.Contains(logStr, "at=httperror.go") { |
| 69 | t.Errorf("expected httperror stack frames to be skipped but got:\n%s", logStr) |
| 70 | } |
| 71 | if !strings.Contains(logStr, "status=500") { |
| 72 | t.Errorf("expected status code of default error info but got:\n%s", logStr) |
| 73 | } |
| 74 | t.Log(logStr) |
| 75 | } |