helper/schema: internal validate as part of provider validation
[GH-1291]
This commit is contained in:
parent
642bdd585f
commit
e36597cad7
|
@ -97,6 +97,13 @@ func (p *Provider) Input(
|
|||
|
||||
// Validate implementation of terraform.ResourceProvider interface.
|
||||
func (p *Provider) Validate(c *terraform.ResourceConfig) ([]string, []error) {
|
||||
if err := p.InternalValidate(); err != nil {
|
||||
return nil, []error{fmt.Errorf(
|
||||
"Internal validation of the provider failed! This is always a bug\n"+
|
||||
"with the provider itself, and not a user issue. Please report\n"+
|
||||
"this bug:\n\n%s", err)}
|
||||
}
|
||||
|
||||
return schemaMap(p.Schema).Validate(c)
|
||||
}
|
||||
|
||||
|
|
|
@ -117,6 +117,36 @@ func TestProviderResources(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProviderValidate(t *testing.T) {
|
||||
cases := []struct {
|
||||
P *Provider
|
||||
Config map[string]interface{}
|
||||
Err bool
|
||||
}{
|
||||
{
|
||||
P: &Provider{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{},
|
||||
},
|
||||
},
|
||||
Config: nil,
|
||||
Err: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
c, err := config.NewRawConfig(tc.Config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
_, es := tc.P.Validate(terraform.NewResourceConfig(c))
|
||||
if (len(es) > 0) != tc.Err {
|
||||
t.Fatalf("%d: %#v", i, es)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderValidateResource(t *testing.T) {
|
||||
cases := []struct {
|
||||
P *Provider
|
||||
|
|
Loading…
Reference in New Issue