config: validation error when output is missing value field
Also lists out invalid keys in errmsg when they are present Closes #4398
This commit is contained in:
parent
2dff310b8b
commit
87a9701f91
|
@ -500,16 +500,23 @@ func (c *Config) Validate() error {
|
||||||
|
|
||||||
// Check that all outputs are valid
|
// Check that all outputs are valid
|
||||||
for _, o := range c.Outputs {
|
for _, o := range c.Outputs {
|
||||||
invalid := false
|
var invalidKeys []string
|
||||||
for k, _ := range o.RawConfig.Raw {
|
valueKeyFound := false
|
||||||
if k != "value" {
|
for k := range o.RawConfig.Raw {
|
||||||
invalid = true
|
if k == "value" {
|
||||||
break
|
valueKeyFound = true
|
||||||
|
} else {
|
||||||
|
invalidKeys = append(invalidKeys, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if invalid {
|
if len(invalidKeys) > 0 {
|
||||||
errs = append(errs, fmt.Errorf(
|
errs = append(errs, fmt.Errorf(
|
||||||
"%s: output should only have 'value' field", o.Name))
|
"%s: output has invalid keys: %s",
|
||||||
|
o.Name, strings.Join(invalidKeys, ", ")))
|
||||||
|
}
|
||||||
|
if !valueKeyFound {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"%s: output is missing required 'value' key", o.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range o.RawConfig.Variables {
|
for _, v := range o.RawConfig.Variables {
|
||||||
|
|
|
@ -196,6 +196,13 @@ func TestConfigValidate_outputBadField(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigValidate_outputMissingEquals(t *testing.T) {
|
||||||
|
c := testConfig(t, "validate-output-missing-equals")
|
||||||
|
if err := c.Validate(); err == nil {
|
||||||
|
t.Fatal("should not be valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigValidate_pathVar(t *testing.T) {
|
func TestConfigValidate_pathVar(t *testing.T) {
|
||||||
c := testConfig(t, "validate-path-var")
|
c := testConfig(t, "validate-path-var")
|
||||||
if err := c.Validate(); err != nil {
|
if err := c.Validate(); err != nil {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
variable "memory" {}
|
variable "memory" {}
|
||||||
|
|
||||||
output "result" {}
|
output "result" { value = "foo" }
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
output "whoops" {
|
||||||
|
value "wheresmyequals"
|
||||||
|
}
|
Loading…
Reference in New Issue