net/dns: fix crash in tests

Looks like #12346 as submitted with failing tests.

Updates #12346

Change-Id: I582cd0dfb117686330d935d763d972373c5ae598
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/11971/head
Brad Fitzpatrick 6 months ago committed by Brad Fitzpatrick
parent 0219317372
commit 916c4db75b

@ -52,11 +52,13 @@ type Manager struct {
resolver *resolver.Resolver resolver *resolver.Resolver
os OSConfigurator os OSConfigurator
knobs *controlknobs.Knobs knobs *controlknobs.Knobs // or nil
goos string // if empty, gets set to runtime.GOOS goos string // if empty, gets set to runtime.GOOS
} }
// NewManagers created a new manager from the given config. // NewManagers created a new manager from the given config.
//
// knobs may be nil.
func NewManager(logf logger.Logf, oscfg OSConfigurator, health *health.Tracker, dialer *tsdial.Dialer, linkSel resolver.ForwardLinkSelector, knobs *controlknobs.Knobs, goos string) *Manager { func NewManager(logf logger.Logf, oscfg OSConfigurator, health *health.Tracker, dialer *tsdial.Dialer, linkSel resolver.ForwardLinkSelector, knobs *controlknobs.Knobs, goos string) *Manager {
if dialer == nil { if dialer == nil {
panic("nil Dialer") panic("nil Dialer")
@ -296,7 +298,7 @@ func (m *Manager) compileConfig(cfg Config) (rcfg resolver.Config, ocfg OSConfig
} }
func (m *Manager) disableSplitDNSOptimization() bool { func (m *Manager) disableSplitDNSOptimization() bool {
return m.knobs.DisableSplitDNSWhenNoCustomResolvers.Load() return m.knobs != nil && m.knobs.DisableSplitDNSWhenNoCustomResolvers.Load()
} }
// toIPsOnly returns only the IP portion of dnstype.Resolver. // toIPsOnly returns only the IP portion of dnstype.Resolver.

@ -11,6 +11,8 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
"tailscale.com/control/controlknobs"
"tailscale.com/health"
"tailscale.com/net/dns/resolver" "tailscale.com/net/dns/resolver"
"tailscale.com/net/netmon" "tailscale.com/net/netmon"
"tailscale.com/net/tsdial" "tailscale.com/net/tsdial"
@ -858,7 +860,8 @@ func TestManager(t *testing.T) {
if goos == "" { if goos == "" {
goos = "linux" goos = "linux"
} }
m := NewManager(t.Logf, &f, nil, tsdial.NewDialer(netmon.NewStatic()), nil, nil, goos) knobs := &controlknobs.Knobs{}
m := NewManager(t.Logf, &f, new(health.Tracker), tsdial.NewDialer(netmon.NewStatic()), nil, knobs, goos)
m.resolver.TestOnlySetHook(f.SetResolver) m.resolver.TestOnlySetHook(f.SetResolver)
if err := m.Set(test.in); err != nil { if err := m.Set(test.in); err != nil {

Loading…
Cancel
Save