helper/schema: Add test for wrong timeout type

This commit is contained in:
Radek Simko 2018-11-05 12:21:37 +00:00
parent 06a74a2dac
commit 186a6dcc38
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
1 changed files with 49 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package schema
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"testing" "testing"
"time" "time"
@ -277,6 +278,54 @@ func TestProviderValidate(t *testing.T) {
} }
} }
func TestProviderDiff_timeoutInvalidType(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{}{
map[string]interface{}{
"create": "40m",
},
},
}
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 type")
}
expectedErrMsg := "Invalid Timeout structure"
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