Merge pull request #9730 from hashicorp/b-schema-validate
helper/schema: validate Read, Delete are set
This commit is contained in:
commit
75f18492f0
|
@ -317,6 +317,14 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap, writable bool) error
|
||||||
|
|
||||||
tsm = schemaMap(r.Schema)
|
tsm = schemaMap(r.Schema)
|
||||||
|
|
||||||
|
// Destroy, and Read are required
|
||||||
|
if r.Read == nil {
|
||||||
|
return fmt.Errorf("Read must be implemented")
|
||||||
|
}
|
||||||
|
if r.Delete == nil {
|
||||||
|
return fmt.Errorf("Delete must be implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// If we have an importer, we need to verify the importer.
|
// If we have an importer, we need to verify the importer.
|
||||||
if r.Importer != nil {
|
if r.Importer != nil {
|
||||||
if err := r.Importer.InternalValidate(); err != nil {
|
if err := r.Importer.InternalValidate(); err != nil {
|
||||||
|
|
|
@ -480,13 +480,49 @@ func TestResourceInternalValidate(t *testing.T) {
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// writable must have Read
|
||||||
|
{
|
||||||
|
&Resource{
|
||||||
|
Create: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Update: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Delete: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"goo": &Schema{
|
||||||
|
Type: TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
|
// writable must have Delete
|
||||||
|
{
|
||||||
|
&Resource{
|
||||||
|
Create: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Read: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Update: func(d *ResourceData, meta interface{}) error { return nil },
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"goo": &Schema{
|
||||||
|
Type: TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
err := tc.In.InternalValidate(schemaMap{}, tc.Writable)
|
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
|
||||||
if err != nil != tc.Err {
|
err := tc.In.InternalValidate(schemaMap{}, tc.Writable)
|
||||||
t.Fatalf("%d: bad: %s", i, err)
|
if err != nil != tc.Err {
|
||||||
}
|
t.Fatalf("%d: bad: %s", i, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue