-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_metadata_test.go
More file actions
53 lines (49 loc) · 1.23 KB
/
extract_metadata_test.go
File metadata and controls
53 lines (49 loc) · 1.23 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import "testing"
func setupTests(t *testing.T) {
t.Setenv("TICKET_DISPATCHER_DOMAIN", "issues.example.com")
t.Setenv("WHITELIST_DOMAIN", "example.com")
t.Setenv("GITHUB_PROJECT", "example/repo")
loadConfig()
}
func TestExtractIssueNumber(t *testing.T) {
setupTests(t)
tests := []struct {
to string
want string
}{{
to: "John Doe <johndoe@example.com>",
want: "",
},
{to: "John Doe <johndoe@example.com>, 123@issues.example.com",
want: "123",
},
}
for _, tc := range tests {
t.Run(tc.to, func(t *testing.T) {
got := extractIssueNumber(tc.to, "")
if got != tc.want {
t.Errorf("extractIssueNumber mismatch:\n--- got ---\n%q\n--- want ---\n%q\n", got, tc.want)
}
})
}
}
func TestExtractSenderDomain(t *testing.T) {
setupTests(t)
tests := []struct {
from string
want string
}{
{from: "John Doe <john.doe@example.com", want: "example.com"},
{from: "jane.doe@example.com", want: "example.com"},
{from: "rincewind@unseen.ac.uk", want: "unseen.ac.uk"},
}
for _, tc := range tests {
t.Run(tc.from, func(t *testing.T) {
got := extractSenderDomain(tc.from)
if got != tc.want {
t.Errorf("extractSenderDomain mismatch:\n--- got ---\n%q\n--- want ---\n%q\n", got, tc.want)
}
})
}
}