helper/schema: Add test for invalid timeout value

This commit is contained in:
Radek Simko 2018-11-05 12:16:11 +00:00
parent 2fe3f16cb3
commit 82a77f9bb5
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
1 changed files with 46 additions and 0 deletions

View File

@ -326,6 +326,52 @@ func TestProviderDiff_timeoutInvalidType(t *testing.T) {
} }
} }
func TestProviderDiff_timeoutInvalidValue(t *testing.T) {
p := &Provider{
ResourcesMap: map[string]*Resource{
"blah": &Resource{
Schema: map[string]*Schema{
"foo": {
Type: TypeInt,
Optional: true,
},
},
Timeouts: &ResourceTimeout{
Create: DefaultTimeout(10 * time.Minute),
},
},
},
}
invalidCfg := map[string]interface{}{
"foo": 42,
"timeouts": map[string]interface{}{
"create": "invalid",
},
}
ic, err := config.NewRawConfig(invalidCfg)
if err != nil {
t.Fatalf("err: %s", err)
}
_, err = p.Diff(
&terraform.InstanceInfo{
Type: "blah",
},
nil,
terraform.NewResourceConfig(ic),
)
if err == nil {
t.Fatal("Expected provider.Diff to fail with invalid timeout value")
}
expectedErrMsg := "time: invalid duration invalid"
if !strings.Contains(err.Error(), expectedErrMsg) {
t.Fatalf("Unexpected error message: %q\nExpected message to contain %q",
err.Error(),
expectedErrMsg)
}
}
func TestProviderValidateResource(t *testing.T) { func TestProviderValidateResource(t *testing.T) {
cases := []struct { cases := []struct {
P *Provider P *Provider