Fix logic when skipping schema input
The Required||Optional logic in schemaMap.Input was incorrect, causing it to always request input. Fix the logic, and the associated tests which were passing "just because".
This commit is contained in:
parent
d55e1bcf58
commit
efd0f5b0db
|
@ -477,7 +477,9 @@ func (m schemaMap) Input(
|
||||||
|
|
||||||
// Skip things that don't require config, if that is even valid
|
// Skip things that don't require config, if that is even valid
|
||||||
// for a provider schema.
|
// for a provider schema.
|
||||||
if !v.Required && !v.Optional {
|
// Required XOR Optional must always be true to validate, so we only
|
||||||
|
// need to check one.
|
||||||
|
if v.Optional {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3173,7 +3173,7 @@ func TestSchemaMap_Input(t *testing.T) {
|
||||||
* String decode
|
* String decode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"uses input on optional field with no config": {
|
"no input on optional field with no config": {
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"availability_zone": &Schema{
|
"availability_zone": &Schema{
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
|
@ -3181,15 +3181,9 @@ func TestSchemaMap_Input(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Input: map[string]string{
|
Input: map[string]string{},
|
||||||
"availability_zone": "foo",
|
Result: map[string]interface{}{},
|
||||||
},
|
Err: false,
|
||||||
|
|
||||||
Result: map[string]interface{}{
|
|
||||||
"availability_zone": "foo",
|
|
||||||
},
|
|
||||||
|
|
||||||
Err: false,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"input ignored when config has a value": {
|
"input ignored when config has a value": {
|
||||||
|
@ -3276,7 +3270,7 @@ func TestSchemaMap_Input(t *testing.T) {
|
||||||
DefaultFunc: func() (interface{}, error) {
|
DefaultFunc: func() (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
Optional: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3290,6 +3284,22 @@ func TestSchemaMap_Input(t *testing.T) {
|
||||||
|
|
||||||
Err: false,
|
Err: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"input not used when optional default function returns nil": {
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"availability_zone": &Schema{
|
||||||
|
Type: TypeString,
|
||||||
|
DefaultFunc: func() (interface{}, error) {
|
||||||
|
return nil, nil
|
||||||
|
},
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Input: map[string]string{},
|
||||||
|
Result: map[string]interface{}{},
|
||||||
|
Err: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue