-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver_srv_test.go
60 lines (58 loc) · 1.27 KB
/
resolver_srv_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
package resolver
import (
"context"
"strings"
"testing"
)
// revive:disable:cognitive-complexity
func TestLookupSRV(t *testing.T) {
tests := []struct {
service, proto, name string
cname, target string
}{
{
"ldap", "tcp", "google.com",
"google.com", "google.com",
},
{
"ldap", "tcp", "google.com.",
"google.com", "google.com",
},
{
"", "", "_ldap._tcp.google.com",
"google.com", "google.com",
},
{
"", "", "_ldap._tcp.google.com.",
"google.com", "google.com",
},
}
ctx := context.Background()
l, err := NewRootResolver("")
if err != nil {
t.Fatal(err)
}
for i := 0; i < len(tests); i++ {
tt := tests[i]
cname, srvs, err := l.LookupSRV(ctx, tt.service, tt.proto, tt.name)
if err != nil {
t.Fatal(err)
}
if len(srvs) == 0 {
t.Error("ERROR: got no record")
}
if !hasSuffixFold(cname, tt.cname) {
t.Errorf("ERROR: got %s; want %s", cname, tt.cname)
}
for _, srv := range srvs {
if !hasSuffixFold(srv.Target, tt.target) {
t.Errorf("ERROR: got %v; want a record containing %s", srv, tt.target)
} else {
t.Logf("got %v; want a record containing %s", srv, tt.target)
}
}
}
}
func hasSuffixFold(s, suffix string) bool {
return strings.HasSuffix(strings.ToLower(s), strings.ToLower(suffix))
}