agent: return empty config for empty config dirs
This commit is contained in:
parent
5c6fe56764
commit
7bb41d2f21
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue