-
Notifications
You must be signed in to change notification settings - Fork 3
/
addresses_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(`.*`), "user@example.com"}
if addr := rewriter.Rewrite("test@example.com"); addr != "user@example.com" {
t.Errorf("expected no rewrite for test@example.com, got %s", addr)
}
}
func TestRewriteMatching(t *testing.T) {
rewriter := &AddressRewriter{regexp.MustCompile(`failmail\+([^@]*)@example.com`), "$1@example.com"}
if addr := rewriter.Rewrite("test@example.com"); addr != "test@example.com" {
t.Errorf("expected no rewrite for test@example.com, got %s", addr)
}
if addr := rewriter.Rewrite("failmail+user@example.com"); addr != "user@example.com" {
t.Errorf("expected rewrite to user@example.com, got %s", addr)
}
}
func TestRewriteAll(t *testing.T) {
rewriter := &AddressRewriter{regexp.MustCompile(`failmail\+([^@]*)@example.com`), "$1@example.com"}
results := rewriter.RewriteAll([]string{"test@example.com", "failmail+test@example.com", "root@example.com"})
if !reflect.DeepEqual(results, []string{"root@example.com", "test@example.com"}) {
t.Errorf("expected 2 unique rewritten addresses, got %v", results)
}
}