-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdns_test.go
45 lines (33 loc) · 887 Bytes
/
dns_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
package dns_test
import (
"context"
"net"
"testing"
"github.com/9seconds/httransform/v2/cache"
"github.com/9seconds/httransform/v2/dns"
"github.com/stretchr/testify/suite"
)
type DNSTestSuite struct {
suite.Suite
cache dns.Interface
}
func (suite *DNSTestSuite) SetupTest() {
suite.cache = dns.New(dns.CacheSize, dns.CacheTTL, cache.NoopEvictCallback)
}
func (suite *DNSTestSuite) TestResolveNames() {
ctx := context.Background()
names, err := suite.cache.Lookup(ctx, "amazon.com")
suite.NoError(err)
names2, err := net.DefaultResolver.LookupHost(ctx, "amazon.com")
suite.NoError(err)
suite.ElementsMatch(names, names2)
}
func (suite *DNSTestSuite) TestResolveIP() {
ctx := context.Background()
names, err := suite.cache.Lookup(ctx, "64.233.165.102")
suite.NoError(err)
suite.NotEmpty(names)
}
func TestDNS(t *testing.T) {
suite.Run(t, &DNSTestSuite{})
}