mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
parse.HostPortorFile: return error when 0 found (#3742)
* parse.HostPortorFile: return error when 0 found Return an error when we haven't found any nameservers. This is the alternative considered in #3735. It's also slighly less code to be changing. Replaces: #3741 Closes: #3741 #3735 Signed-off-by: Miek Gieben <miek@miek.nl> * Add extra test case here as well Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -139,6 +139,8 @@ nameserver 10.10.255.253`), 0666); err != nil {
|
|||||||
}{
|
}{
|
||||||
// pass
|
// pass
|
||||||
{`forward . ` + resolv, false, "", []string{"10.10.255.252:53", "10.10.255.253:53"}},
|
{`forward . ` + resolv, false, "", []string{"10.10.255.252:53", "10.10.255.253:53"}},
|
||||||
|
// fail
|
||||||
|
{`forward . /dev/null`, true, "no nameservers", nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
@@ -168,6 +170,9 @@ nameserver 10.10.255.253`), 0666); err != nil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if test.shouldErr {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, p := range f.proxies {
|
for _, p := range f.proxies {
|
||||||
p.health.Check(p) // this should almost always err, we don't care it shouldn't crash
|
p.health.Check(p) // this should almost always err, we don't care it shouldn't crash
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ func HostPortOrFile(s ...string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
servers = append(servers, h)
|
servers = append(servers, h)
|
||||||
}
|
}
|
||||||
|
if len(servers) == 0 {
|
||||||
|
return servers, fmt.Errorf("no nameservers found")
|
||||||
|
}
|
||||||
return servers, nil
|
return servers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ func TestHostPortOrFile(t *testing.T) {
|
|||||||
"[fd01::1%ens3]:153",
|
"[fd01::1%ens3]:153",
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"8.9.1043",
|
||||||
|
"",
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ioutil.WriteFile("resolv.conf", []byte("nameserver 127.0.0.1\n"), 0600)
|
err := ioutil.WriteFile("resolv.conf", []byte("nameserver 127.0.0.1\n"), 0600)
|
||||||
|
|||||||
Reference in New Issue
Block a user