-
Notifications
You must be signed in to change notification settings - Fork 32
/
options_test.go
55 lines (48 loc) · 1.3 KB
/
options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package retryabledns
import (
"net"
"testing"
stringsutil "github.com/projectdiscovery/utils/strings"
"github.com/stretchr/testify/require"
)
func TestSetLocalAddrIPFromNetInterface(t *testing.T) {
options := Options{
MaxRetries: 0,
}
// search loopback interface
interfaces, err := net.Interfaces()
require.Nil(t, err)
for _, iface := range interfaces {
if iface.Flags&net.FlagLoopback != 0 {
err := options.SetLocalAddrIPFromNetInterface(iface.Name)
require.Nil(t, err)
require.NotNil(t, options.LocalAddrIP)
require.True(t, stringsutil.EqualFoldAny(options.LocalAddrIP.String(), "127.0.0.1", "::1"))
}
}
// Should error with invalid interface name
err = options.SetLocalAddrIPFromNetInterface("lo1234")
require.NotNil(t, err)
}
func TestValidateOptions(t *testing.T) {
t.Run("empty options", func(t *testing.T) {
options := Options{}
err := options.Validate()
require.NotNil(t, err)
})
t.Run("max retries errors with zero", func(t *testing.T) {
options := Options{
MaxRetries: 0,
}
err := options.Validate()
require.ErrorIs(t, err, ErrMaxRetriesZero)
})
t.Run("base resolvers errors if empty", func(t *testing.T) {
options := Options{
MaxRetries: 1,
BaseResolvers: []string{},
}
err := options.Validate()
require.ErrorIs(t, err, ErrResolversEmpty)
})
}