zettio/weave#362 - new constructor for creating a DNS server with a given config

fix unit tests by using the new constructor
This commit is contained in:
Alvaro Saurin committed 2015-02-23 13:17:54 +01:00
1 parent 3be5600383
commit c1f9c8bc10
2 files changed
+15 -8

No files matched your search

+12 -7
View File
@@ -28,13 +28,8 @@ type DNSServer struct {
tcpPort int
}
// Creates a new DNS server
func NewDNSServer(zone Zone, iface *net.Interface, udpPort int, tcpPort int) (*DNSServer, error) {
config, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
return nil, err
}
// Creates a new DNS server with a given config
func NewDNSServerWithConfig(config *dns.ClientConfig, zone Zone, iface *net.Interface, udpPort int, tcpPort int) (*DNSServer, error) {
return &DNSServer{
config: config,
zone: zone,
@@ -44,6 +39,16 @@ func NewDNSServer(zone Zone, iface *net.Interface, udpPort int, tcpPort int) (*D
}, nil
}
// Creates a new DNS server
func NewDNSServer(zone Zone, iface *net.Interface, udpPort int, tcpPort int) (*DNSServer, error) {
config, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
return nil, err
}
return NewDNSServerWithConfig(config, zone, iface, udpPort, tcpPort)
}
// Start the DNS server
func (s *DNSServer) Start() error {
mdnsClient, err := NewMDNSClient()
+3 -1
View File
@@ -41,7 +41,9 @@ func TestDNSServer(t *testing.T) {
wt.AssertNoErr(t, err)
config := &dns.ClientConfig{Servers: []string{"127.0.0.1"}, Port: fallbackPort}
go startServerWithConfig(config, zone, nil, port, 0)
srv, err := NewDNSServerWithConfig(config, zone, nil, port, port)
wt.AssertNoErr(t, err)
go srv.Start()
time.Sleep(100 * time.Millisecond) // Allow sever goroutine to start
c := new(dns.Client)