Files
gluetun/internal/updater/resolver/ips_test.go
Quentin McGaw d5ef3de64c Feature: more robust updater DNS resolution
- Parallel resolver to resolve multiple hosts
- Repeat resolver to repeat resolution for a single host
- Additional parameters for fault toleration
- Do not update servers if e.g. > 10% DNS resolutions failed
- resolver package in updater package
2021-05-06 18:48:14 +00:00

42 lines
858 B
Go

package resolver
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_uniqueIPsToSlice(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
inputIPs map[string]struct{}
outputIPs []net.IP
}{
"nil": {
inputIPs: nil,
outputIPs: []net.IP{},
},
"empty": {
inputIPs: map[string]struct{}{},
outputIPs: []net.IP{},
},
"single IPv4": {
inputIPs: map[string]struct{}{"1.1.1.1": {}},
outputIPs: []net.IP{{1, 1, 1, 1}},
},
"two IPv4s": {
inputIPs: map[string]struct{}{"1.1.1.1": {}, "1.1.2.1": {}},
outputIPs: []net.IP{{1, 1, 1, 1}, {1, 1, 2, 1}},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
outputIPs := uniqueIPsToSlice(testCase.inputIPs)
assert.Equal(t, testCase.outputIPs, outputIPs)
})
}
}