-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddresses_test.go
36 lines (28 loc) · 1.17 KB
/
addresses_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"reflect"
"regexp"
"testing"
)
func TestRewriteEverything(t *testing.T) {
rewriter := &AddressRewriter{regexp.MustCompile(`.*`), "[email protected]"}
if addr := rewriter.Rewrite("[email protected]"); addr != "[email protected]" {
t.Errorf("expected no rewrite for [email protected], got %s", addr)
}
}
func TestRewriteMatching(t *testing.T) {
rewriter := &AddressRewriter{regexp.MustCompile(`failmail\+([^@]*)@example.com`), "[email protected]"}
if addr := rewriter.Rewrite("[email protected]"); addr != "[email protected]" {
t.Errorf("expected no rewrite for [email protected], got %s", addr)
}
if addr := rewriter.Rewrite("[email protected]"); addr != "[email protected]" {
t.Errorf("expected rewrite to [email protected], got %s", addr)
}
}
func TestRewriteAll(t *testing.T) {
rewriter := &AddressRewriter{regexp.MustCompile(`failmail\+([^@]*)@example.com`), "[email protected]"}
results := rewriter.RewriteAll([]string{"[email protected]", "[email protected]", "[email protected]"})
if !reflect.DeepEqual(results, []string{"[email protected]", "[email protected]"}) {
t.Errorf("expected 2 unique rewritten addresses, got %v", results)
}
}