Skip to content

Commit 78405ef

Browse files
committed
s/SetSystemServers/SetBootstrapServers/
1 parent eda7056 commit 78405ef

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

resolver.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,19 @@ func New() *Resolver {
8484
}
8585
}
8686

87-
// SetSystemServers specifies the IP addresses and, optionally, ports for the
88-
// resolver(s) of the operating system. These servers are only used to discover
89-
// the root name servers.
87+
// SetBootstrapServers specifies the IP addresses and, optionally, ports for
88+
// the name servers that are used to discover the root name servers. By
89+
// default the name servers configured in the operating system are used.
9090
//
9191
// This method is intended mostly for testing this package, but is also useful
9292
// if the operating system's resolver can't be trusted to query the root zone
9393
// correctly, or if automatic detection fails.
9494
//
95-
// If SetSystemServers has not been called when Query is first called, Resolver
95+
// If SetBootstrapServers has not been called when Query is first called, Resolver
9696
// will attempt to discover the operating system's resolver(s). This is
9797
// platform specific. For instance, on *nix systems, /etc/resolv.conf is
9898
// parsed.
99-
//
100-
// Calling SetSystemServers after the first call to Query has no effect,
101-
// because these servers are only used once to discover the root servers and
102-
// the list of root servers is cached forever.
103-
func (r *Resolver) SetSystemServers(serverAddresses ...string) error {
99+
func (r *Resolver) SetBootstrapServers(serverAddresses ...string) error {
104100
serverAddresses, err := r.normalizeAddrs(serverAddresses)
105101
if err != nil {
106102
return err
@@ -128,7 +124,7 @@ func (r *Resolver) normalizeAddrs(addrs []string) ([]string, error) {
128124
}
129125

130126
if port == "" {
131-
port = "53"
127+
port = r.defaultPort
132128
}
133129
addr = net.JoinHostPort(ip, port)
134130

resolver_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package dnsresolver
33
import (
44
"context"
55
"errors"
6-
"net"
76
"strings"
87
"testing"
98
"time"
@@ -12,29 +11,29 @@ import (
1211
"github.com/stretchr/testify/assert"
1312
)
1413

15-
func TestResolver_SetSystemServers_AddressNormalization(t *testing.T) {
14+
func TestResolver_SetBootstrapServers_AddressNormalization(t *testing.T) {
1615
t.Parallel()
1716

1817
t.Run("valid", func(t *testing.T) {
1918
r := New()
2019

21-
err := r.SetSystemServers("127.0.0.1", "127.0.0.2:5353")
20+
err := r.SetBootstrapServers("127.0.0.1", "127.0.0.2:5353")
2221

2322
assert.NoError(t, err)
2423
assert.Equal(t, r.systemServerAddrs, []string{"127.0.0.1:53", "127.0.0.2:5353"})
2524
})
2625
t.Run("unique", func(t *testing.T) {
2726
r := New()
2827

29-
err := r.SetSystemServers("127.0.0.1", "127.0.0.1:53")
28+
err := r.SetBootstrapServers("127.0.0.1", "127.0.0.1:53")
3029

3130
assert.NoError(t, err)
3231
assert.Equal(t, r.systemServerAddrs, []string{"127.0.0.1:53"})
3332
})
3433
t.Run("invalid", func(t *testing.T) {
3534
r := New()
3635

37-
err := r.SetSystemServers("127.0.0.1", "localhost:5353")
36+
err := r.SetBootstrapServers("127.0.0.1", "localhost:5353")
3837

3938
assert.EqualError(t, err, "not an ip address: localhost:5353")
4039
assert.Len(t, r.systemServerAddrs, 0)
@@ -50,7 +49,7 @@ func TestResolver_Query_SimpleARecord(t *testing.T) {
5049
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
5150
expSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
5251

53-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
52+
r.SetBootstrapServers(rootSrv.IP())
5453

5554
rootSrv.ExpectQuery("A www.example.com.").DelegateTo("com.", comSrv.IP())
5655
comSrv.ExpectQuery("A www.example.com.").DelegateTo("example.com.", expSrv.IP()).ViaAuthoritySection()
@@ -103,7 +102,7 @@ func TestResolver_Query_Fallback(t *testing.T) {
103102
errSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
104103
expSrv := NewTestServer(t, "127.0.0.102:"+r.defaultPort)
105104

106-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
105+
r.SetBootstrapServers(rootSrv.IP())
107106

108107
rootSrv.ExpectQuery("A www.example.com.").DelegateTo("com.", comSrv.IP())
109108
comSrv.ExpectQuery("A www.example.com.").DelegateTo("example.com.", errSrv.IP(), expSrv.IP())
@@ -159,7 +158,7 @@ func TestResolver_Query_CNAMEResolution(t *testing.T) {
159158
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
160159
expSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
161160

162-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
161+
r.SetBootstrapServers(rootSrv.IP())
163162

164163
rootSrv.ExpectQuery("A example.com.").DelegateTo("com.", comSrv.IP())
165164
comSrv.ExpectQuery("A example.com.").DelegateTo("example.com.", expSrv.IP())
@@ -214,7 +213,7 @@ func TestResolver_Query_ZoneGap(t *testing.T) {
214213
netSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
215214
expSrv := NewTestServer(t, "127.0.0.102:"+r.defaultPort)
216215

217-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
216+
r.SetBootstrapServers(rootSrv.IP())
218217

219218
rootSrv.ExpectQuery("A example.com.").DelegateTo("com.", comSrv.IP())
220219
comSrv.ExpectQuery("A example.com.").DelegateTo("example.com.", "ns1.test.net.")
@@ -281,7 +280,7 @@ func TestResolver_Query_NameFallback(t *testing.T) {
281280
dd24Srv := NewTestServer(t, "127.0.0.103:"+r.defaultPort)
282281
awsSrv := NewTestServer(t, "127.0.0.104:"+r.defaultPort)
283282

284-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
283+
r.SetBootstrapServers(rootSrv.IP())
285284

286285
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
287286
defer cancel()
@@ -353,7 +352,7 @@ func TestResolver_Query_DetectCycle(t *testing.T) {
353352
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
354353
netSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
355354

356-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
355+
r.SetBootstrapServers(rootSrv.IP())
357356

358357
rootSrv.ExpectQuery("A example.com.").DelegateTo("com.", comSrv.IP())
359358
comSrv.ExpectQuery("A example.com.").DelegateTo("example.com.", "ns1.test.net.")
@@ -385,7 +384,7 @@ func TestResolver_Query_NS(t *testing.T) {
385384
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
386385
expSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
387386

388-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
387+
r.SetBootstrapServers(rootSrv.IP())
389388

390389
rootSrv.ExpectQuery("NS www.example.com.").DelegateTo("com.", comSrv.IP())
391390
comSrv.ExpectQuery("NS www.example.com.").DelegateTo("example.com", expSrv.IP())
@@ -420,7 +419,7 @@ func TestResolver_Query_Caching_DefaultPolicy(t *testing.T) {
420419
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
421420
expSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
422421

423-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
422+
r.SetBootstrapServers(rootSrv.IP())
424423

425424
rootSrv.ExpectQuery("NS www.example.com.").DelegateTo("com.", comSrv.IP())
426425
comSrv.ExpectQuery("NS www.example.com.").DelegateTo("example.com.", expSrv.IP())
@@ -459,7 +458,7 @@ func TestResolver_Query_Caching_ObeyResponderAdvice(t *testing.T) {
459458
comSrv := NewTestServer(t, "127.0.0.100:"+r.defaultPort)
460459
expSrv := NewTestServer(t, "127.0.0.101:"+r.defaultPort)
461460

462-
r.systemServerAddrs = []string{net.JoinHostPort(rootSrv.IP(), r.defaultPort)}
461+
r.SetBootstrapServers(rootSrv.IP())
463462

464463
rootSrv.ExpectQuery("A www.example.com.").DelegateTo("com.", comSrv.IP())
465464
comSrv.ExpectQuery("A www.example.com.").DelegateTo("example.com.", expSrv.IP())

0 commit comments

Comments
 (0)