From 99a44393596ca24b8bc24671f7c456500020ab13 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 28 Jul 2014 08:34:43 -0700 Subject: [PATCH] config: nicer error if dir isn't a dir --- config/loader.go | 10 ++++++++++ config/loader_test.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/config/loader.go b/config/loader.go index bfbb3e210..7b3112ad6 100644 --- a/config/loader.go +++ b/config/loader.go @@ -49,6 +49,16 @@ func LoadDir(root string) (*Config, error) { return nil, err } + fi, err := f.Stat() + if err != nil { + return nil, err + } + if !fi.IsDir() { + return nil, fmt.Errorf( + "configuration path must be a directory: %s", + root) + } + err = nil for err != io.EOF { var fis []os.FileInfo diff --git a/config/loader_test.go b/config/loader_test.go index c154075e6..234dac47b 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -149,6 +149,13 @@ func TestLoadDir_basic(t *testing.T) { } } +func TestLoadDir_file(t *testing.T) { + _, err := LoadDir(filepath.Join(fixtureDir, "variables.tf")) + if err == nil { + t.Fatal("should error") + } +} + func TestLoadDir_noConfigs(t *testing.T) { _, err := LoadDir(filepath.Join(fixtureDir, "dir-empty")) if err == nil {