| 1 |
package msg |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestParseUnsubscribe(t *testing.T) { |
| 8 |
type tc struct { |
| 9 |
hdr string |
| 10 |
expected []string |
| 11 |
} |
| 12 |
cases := []*tc{ |
| 13 |
{"", []string{}}, |
| 14 |
{"invalid", []string{}}, |
| 15 |
{"<https://example.com>, <http://example.com>", []string{ |
| 16 |
"https://example.com", "http://example.com", |
| 17 |
}}, |
| 18 |
{"<https://example.com> is a URL", []string{ |
| 19 |
"https://example.com", |
| 20 |
}}, |
| 21 |
{ |
| 22 |
"<mailto:user@host?subject=unsubscribe>, <https://example.com>", |
| 23 |
[]string{ |
| 24 |
"mailto:user@host?subject=unsubscribe", "https://example.com", |
| 25 |
}, |
| 26 |
}, |
| 27 |
{"<>, <https://example> ", []string{ |
| 28 |
"", "https://example", |
| 29 |
}}, |
| 30 |
} |
| 31 |
for _, c := range cases { |
| 32 |
result := parseUnsubscribeMethods(c.hdr) |
| 33 |
if len(result) != len(c.expected) { |
| 34 |
t.Errorf("expected %d methods but got %d", len(c.expected), len(result)) |
| 35 |
continue |
| 36 |
} |
| 37 |
for idx := range result { |
| 38 |
if result[idx].String() != c.expected[idx] { |
| 39 |
t.Errorf("expected %v but got %v", c.expected[idx], result[idx]) |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |