mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
middleware/auto: handle non-existent directory (#385)
Don't panic on a non-existent directory. Add test for it as well. Fixes #384
This commit is contained in:
@@ -23,7 +23,7 @@ func (a Auto) Walk() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, err error) error {
|
||||||
if info.IsDir() {
|
if info == nil || info.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ func TestWalk(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWalkNonExistent(t *testing.T) {
|
||||||
|
log.SetOutput(ioutil.Discard)
|
||||||
|
|
||||||
|
nonExistingDir := "highly_unlikely_to_exist_dir"
|
||||||
|
|
||||||
|
ldr := loader{
|
||||||
|
directory: nonExistingDir,
|
||||||
|
re: regexp.MustCompile(`db\.(.*)`),
|
||||||
|
template: `${1}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
a := Auto{
|
||||||
|
loader: ldr,
|
||||||
|
Zones: &Zones{},
|
||||||
|
}
|
||||||
|
|
||||||
|
a.Walk()
|
||||||
|
}
|
||||||
|
|
||||||
func createFiles() (string, error) {
|
func createFiles() (string, error) {
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
dir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user