forked from zaccone/spf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
51 lines (41 loc) · 1023 Bytes
/
main_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
package spf
import (
"fmt"
"os"
"testing"
"time"
"github.com/miekg/dns"
"github.com/outcaste-io/ristretto"
. "github.com/redsift/spf/v2/testing"
"github.com/redsift/spf/v2/z"
)
var (
testNameServer *dns.Server
testResolverCache *ristretto.Cache
testResolver Resolver
)
func TestMain(m *testing.M) {
var err error
testNameServer, err = StartDNSServer("udp", "127.0.0.1:0")
if err != nil {
panic(fmt.Errorf("unable to run local DNS server: %w", err))
}
dns.HandleFunc(".", RootZone)
defer func() {
dns.HandleRemove(".")
testNameServer.Shutdown()
}()
testResolverCache = z.MustRistrettoCache(&ristretto.Config{
NumCounters: int64(100 * 10),
MaxCost: 1 << 20,
BufferItems: 64,
Metrics: true,
KeyToHash: z.QuestionToHash,
Cost: z.MsgCost,
})
testResolver, _ = NewMiekgDNSResolver(testNameServer.PacketConn.LocalAddr().String(),
MiekgDNSMinSaneTTL(100*time.Millisecond),
MiekgDNSCache(testResolverCache),
MiekgDNSParallelism(1))
os.Exit(m.Run())
}