config: nicer error if dir isn't a dir

This commit is contained in:
Mitchell Hashimoto 2014-07-28 08:34:43 -07:00
parent 80b6640e67
commit 99a4439359
2 changed files with 17 additions and 0 deletions

View File

@ -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

View File

@ -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 {