fix: panicing on options parsing. (#642)
This commit is contained in:
parent
4d25966dce
commit
906238edc6
@ -91,7 +91,7 @@ func ClientConfigFromReader(resolvconf io.Reader) (*ClientConfig, error) {
|
||||
n = 1
|
||||
}
|
||||
c.Timeout = n
|
||||
case len(s) >= 8 && s[:9] == "attempts:":
|
||||
case len(s) >= 9 && s[:9] == "attempts:":
|
||||
n, _ := strconv.Atoi(s[9:])
|
||||
if n < 1 {
|
||||
n = 1
|
||||
|
@ -59,7 +59,35 @@ func TestNdots(t *testing.T) {
|
||||
t.Errorf("Ndots not properly parsed: (Expected: %d / Was: %d)", ndotsVariants[data], cc.Ndots)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientConfigFromReaderAttempts(t *testing.T) {
|
||||
testCases := []struct {
|
||||
data string
|
||||
expected int
|
||||
}{
|
||||
{data: "options attempts:0", expected: 1},
|
||||
{data: "options attempts:1", expected: 1},
|
||||
{data: "options attempts:15", expected: 15},
|
||||
{data: "options attempts:16", expected: 16},
|
||||
{data: "options attempts:-1", expected: 1},
|
||||
{data: "options attempt:", expected: 2},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(strings.Replace(test.data, ":", " ", -1), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cc, err := ClientConfigFromReader(strings.NewReader(test.data))
|
||||
if err != nil {
|
||||
t.Errorf("error parsing resolv.conf: %v", err)
|
||||
}
|
||||
if cc.Attempts != test.expected {
|
||||
t.Errorf("A attempts not properly parsed: (Expected: %d / Was: %d)", test.expected, cc.Attempts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadFromFile(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user