config: nicer error if dir isn't a dir
This commit is contained in:
parent
80b6640e67
commit
99a4439359
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue