config: Don't panic if config directory contains only overrides
This commit is contained in:
parent
8d9b44105a
commit
43dcaa1a00
|
@ -80,7 +80,7 @@ func LoadDir(root string) (*Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) == 0 {
|
||||
if len(files) == 0 && len(overrides) == 0 {
|
||||
return nil, &ErrNoConfigsFound{Dir: root}
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,9 @@ func LoadDir(root string) (*Config, error) {
|
|||
result = c
|
||||
}
|
||||
}
|
||||
if len(files) == 0 {
|
||||
result = &Config{}
|
||||
}
|
||||
|
||||
// Load all the overrides, and merge them into the config
|
||||
for _, f := range overrides {
|
||||
|
|
|
@ -1022,6 +1022,22 @@ func TestLoad_jsonAttributes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoad_onlyOverride(t *testing.T) {
|
||||
c, err := LoadDir(filepath.Join(fixtureDir, "dir-only-override"))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
t.Fatal("config should not be nil")
|
||||
}
|
||||
|
||||
actual := variablesStr(c.Variables)
|
||||
if actual != strings.TrimSpace(dirOnlyOverrideVariablesStr) {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
const jsonAttributeStr = `
|
||||
cloudstack_firewall.test (x1)
|
||||
ipaddress
|
||||
|
@ -1229,6 +1245,12 @@ foo
|
|||
bar
|
||||
`
|
||||
|
||||
const dirOnlyOverrideVariablesStr = `
|
||||
foo
|
||||
bar
|
||||
bar
|
||||
`
|
||||
|
||||
const importProvidersStr = `
|
||||
aws
|
||||
bar
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
variable "foo" {
|
||||
default = "bar"
|
||||
description = "bar"
|
||||
}
|
Loading…
Reference in New Issue