oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3import (
4 "errors"
5 "strings"
6 "testing"
7)
8
9// The logs rule is absolute, and the thing that broke it was not this
10// app's own formatting: rastrillo's mailer puts the recipient into its
11// error, and logging that error verbatim is the obvious careful thing
12// to do. scrub is what makes "log the error" safe.
13func TestScrubTakesAddressesOutOfLogLines(t *testing.T) {
14 cases := []struct {
15 in string
16 want string
17 }{
18 {"send to paul@example.com: connection refused",
19 "send to [address]: connection refused"},
20 {"smtp: 550 5.1.1 <someone.else+tag@sub.example.co.uk> unknown",
21 "smtp: 550 5.1.1 <[address]> unknown"},
22 {"two: a@x.com and b@y.org", "two: [address] and [address]"},
23 {"nothing to redact here", "nothing to redact here"},
24 }
25 for _, c := range cases {
26 if got := scrub(c.in); got != c.want {
27 t.Errorf("scrub(%q) = %q, want %q", c.in, got, c.want)
28 }
29 }
30}
31
32func TestScrubErrHandlesNil(t *testing.T) {
33 if got := scrubErr(nil); got != "" {
34 t.Errorf("scrubErr(nil) = %q, want empty", got)
35 }
36 got := scrubErr(errors.New("dial mail.example.com: no route for bob@example.com"))
37 if strings.Contains(got, "bob@example.com") {
38 t.Errorf("scrubErr left the address in: %q", got)
39 }
40 // The parts that make an error useful must survive.
41 if !strings.Contains(got, "no route") {
42 t.Errorf("scrubErr threw away the diagnosis: %q", got)
43 }
44}
45