Skip to content

Commit

Permalink
Fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip-stephens committed Apr 2, 2024
1 parent a9ac4cc commit 0a68cd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 3 additions & 8 deletions pkg/zdns/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/zmap/dns"
)

type domain_ns struct {
Expand Down Expand Up @@ -57,13 +55,10 @@ func InitTest(t *testing.T) *Resolver {
protocolStatus = make(map[domain_ns]Status)
mockResults = make(map[domain_ns]SingleQueryResult)

r := Resolver{
nameServers: []string{"127.0.0.1"},
udpClient: new(dns.Client),
}
mc := MockLookupClient{}
r.WithLookuper(mc)
return &r
r, err := NewResolverBuilder().WithNameServers([]string{"127.0.0.1"}).WithLookuper(mc).BuildExternalResolver()
assert.NoError(t, err)
return r
}

// Test specifying neither ipv4 not ipv6 flag looks up ipv4 by default
Expand Down
6 changes: 3 additions & 3 deletions pkg/zdns/resolver_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (rc *ResolverConfigurer) BuildIterativeResolver(cache *Cache) (*Resolver, e
}

// isValid checks if the resolver is valid
// Returns true, nil or false, error where error describes what is invalid about the resolver configurer. Called before building the resolver
// Returns whether the resolver configurer is valid or not and if invalid, why. Called before building the resolver.
func (rc *ResolverConfigurer) isValid() (bool, string) {
if rc.hasBeenBuilt {
return false, "cannot change resolver builder after resolver has been built"
Expand All @@ -213,8 +213,8 @@ func (rc *ResolverConfigurer) isValid() (bool, string) {

// buildResolverHelper has the common build logic for all resolvers
func (rc *ResolverConfigurer) buildResolverHelper() (*Resolver, error) {
if isValid, err := rc.isValid(); !isValid {
return nil, fmt.Errorf("invalid resolver: %w", err)
if isValid, notValidReason := rc.isValid(); !isValid {
return nil, fmt.Errorf("invalid resolver: %s", notValidReason)
}
log.SetLevel(rc.r.logLevel)
if !rc.localAddrSet {
Expand Down

0 comments on commit 0a68cd3

Please sign in to comment.