Merge pull request #2451 from hashicorp/b-provider-validate

helper/schema: internal validate as part of provider validation
This commit is contained in:
Mitchell Hashimoto 2015-06-24 10:28:49 -07:00
commit 630646335f
2 changed files with 37 additions and 0 deletions

View File

@ -97,6 +97,13 @@ func (p *Provider) Input(
// Validate implementation of terraform.ResourceProvider interface. // Validate implementation of terraform.ResourceProvider interface.
func (p *Provider) Validate(c *terraform.ResourceConfig) ([]string, []error) { 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) return schemaMap(p.Schema).Validate(c)
} }

View File

@ -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) { func TestProviderValidateResource(t *testing.T) {
cases := []struct { cases := []struct {
P *Provider P *Provider