added test

This commit is contained in:
Dimitri Herzog 2021-09-08 22:50:44 +02:00
parent af3a9507e9
commit ea3b5dee50
1 changed files with 50 additions and 0 deletions

50
util/bootstrap_test.go Normal file
View File

@ -0,0 +1,50 @@
package util
import (
"github.com/0xERR0R/blocky/config"
"github.com/0xERR0R/blocky/helpertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"golang.org/x/net/context"
)
var _ = Describe("Bootstrap resolver configuration", func() {
Describe("Default config", func() {
When("BootstrapDns is not configured", func() {
dialer := Dialer(&config.Config{})
It("should return a dealer without custom resolver", func() {
Expect(dialer.Resolver).Should(BeNil())
})
})
When("BootstrapDns is configured UDP resolver", func() {
dialer := Dialer(&config.Config{
BootstrapDNS: config.Upstream{
Net: config.NetTCPUDP,
Host: "0.0.0.0",
Port: 53,
},
})
It("should return a dealer with custom resolver", func() {
Expect(dialer.Resolver).Should(Not(BeNil()))
_, err := dialer.Resolver.Dial(context.Background(), "udp", "test")
Expect(err).Should(Succeed())
})
})
When("BootstrapDns has wrong (https) configuration", func() {
It("should log fatal error", func() {
helpertest.ShouldLogFatal(func() {
Dialer(&config.Config{
BootstrapDNS: config.Upstream{
Net: config.NetHTTPS,
Host: "1.1.1.1",
Port: 53,
},
})
})
})
})
})
})