-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocketmap_test.go
50 lines (48 loc) · 1.4 KB
/
socketmap_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
package srsmilter
import (
"net"
"testing"
)
func TestSocketmap(t *testing.T) {
t.Cleanup(monkeyPatch().Reset)
conf := &Configuration{
SrsDomain: "srs.example.com",
LocalDomains: []Domain{ToDomain("example.com")},
SrsKeys: []string{"secret-key"},
LocalIps: []net.IP{net.ParseIP("8.8.8.8")},
LogLevel: 3,
}
conf.Setup()
type args struct {
lookup string
key string
}
tests := []struct {
name string
args args
wantResult string
wantFound bool
wantErr bool
}{
{"wrong map", args{"wrong", ""}, "", false, false},
{"no email", args{"decode", "something"}, "", false, false},
{"no SRS", args{"decode", "root@localhost"}, "", false, false},
{"SRS", args{"decode", "[email protected]"}, "[email protected]", true, false},
{"SRS-error", args{"decode", "[email protected]"}, "", false, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotResult, gotFound, err := Socketmap(conf, tt.args.lookup, tt.args.key)
if (err != nil) != tt.wantErr {
t.Errorf("Socketmap() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotResult != tt.wantResult {
t.Errorf("Socketmap() gotResult = %v, want %v", gotResult, tt.wantResult)
}
if gotFound != tt.wantFound {
t.Errorf("Socketmap() gotFound = %v, want %v", gotFound, tt.wantFound)
}
})
}
}