-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrs_test.go
84 lines (81 loc) · 2.15 KB
/
srs_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package srsmilter
import "testing"
func TestForwardSrs(t *testing.T) {
c2 := &Configuration{
SrsDomain: "srs.example.com",
SrsKeys: []string{},
}
c3 := &Configuration{
SrsDomain: "srs.example.com",
SrsKeys: []string{"secret-key", "another"},
}
type args struct {
addr string
config *Configuration
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"no key", args{"abc", c2}, "", true},
{"not-an-email", args{"hello - at - example.com", c3}, "", true},
{"my-srs-key-rotation", args{"[email protected]", c3}, "[email protected]", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Cleanup(monkeyPatch().Reset)
got, err := ForwardSrs(tt.args.addr, tt.args.config)
if (err != nil) != tt.wantErr {
t.Errorf("ForwardSrs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ForwardSrs() got = %v, want %v", got, tt.want)
}
})
}
}
func TestReverseSrs(t *testing.T) {
c1 := &Configuration{
SrsDomain: "srs.example.com",
SrsKeys: []string{"one", "two"},
}
c2 := &Configuration{
SrsDomain: "srs.example.com",
SrsKeys: []string{},
}
c3 := &Configuration{
SrsDomain: "srs.example.com",
SrsKeys: []string{"one", "secret-key"},
}
type args struct {
srsAddress string
config *Configuration
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"no key", args{"abc", c2}, "", true},
{"not-my-srs", args{"[email protected]", c1}, "", true},
{"not-an-address", args{"hello - at - example.com", c1}, "", true},
{"my-srs-key-rotation", args{"[email protected]", c3}, "[email protected]", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Cleanup(monkeyPatch().Reset)
got, err := ReverseSrs(tt.args.srsAddress, tt.args.config)
if (err != nil) != tt.wantErr {
t.Errorf("ReverseSrs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ReverseSrs() got = %v, want %v", got, tt.want)
}
})
}
}