agent: return empty config for empty config dirs

This commit is contained in:
Ryan Uber 2015-09-29 15:07:41 -07:00
parent 5c6fe56764
commit 7bb41d2f21
2 changed files with 15 additions and 1 deletions

View file

@ -561,6 +561,11 @@ func LoadConfigDir(dir string) (*Config, error) {
}
}
// Fast-path if we have no files
if len(files) == 0 {
return &Config{}, nil
}
var result *Config
for _, f := range files {
config, err := LoadConfigFile(f)

View file

@ -170,6 +170,15 @@ func TestConfig_LoadConfigDir(t *testing.T) {
}
defer os.RemoveAll(dir)
// Returns empty config on empty dir
config, err := LoadConfig(dir)
if err != nil {
t.Fatalf("err: %s", err)
}
if config == nil {
t.Fatalf("should not be nil")
}
file1 := filepath.Join(dir, "conf1.hcl")
err = ioutil.WriteFile(file1, []byte(`{"region":"west"}`), 0600)
if err != nil {
@ -198,7 +207,7 @@ func TestConfig_LoadConfigDir(t *testing.T) {
}
// Works if configs are valid
config, err := LoadConfigDir(dir)
config, err = LoadConfigDir(dir)
if err != nil {
t.Fatalf("err: %s", err)
}