Commit d3dae8d7 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

middleware/auto: handle non-existent directory (#385)

Don't panic on a non-existent directory. Add test for it as well.

Fixes #384
parent 243797a3
...@@ -23,7 +23,7 @@ func (a Auto) Walk() error { ...@@ -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) { ...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment