diff --git a/pf/tests/provider_configure_test.go b/pf/tests/provider_configure_test.go index 5581ad55e..9debcc48d 100644 --- a/pf/tests/provider_configure_test.go +++ b/pf/tests/provider_configure_test.go @@ -15,6 +15,7 @@ package tfbridgetests import ( + "context" "testing" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -78,7 +79,8 @@ func TestConfigureProperties(t *testing.T) { t.Parallel() rapid.Check(t, func(r *rapid.T) { - schema := propProviderSchema.Schema().Draw(r, "schema") + ctx := context.Background() + schema := propProviderSchema.Schema(ctx).Draw(r, "schema") value := propProviderValue.WithValue(schema).Draw(r, "value") crosstests.Configure(t, schema, value.Tf.AsValueMap(), value.Pu) }) diff --git a/pf/tests/util/property/pf/schema/provider/schema.go b/pf/tests/util/property/pf/schema/provider/schema.go index b3f037857..ba0d4c882 100644 --- a/pf/tests/util/property/pf/schema/provider/schema.go +++ b/pf/tests/util/property/pf/schema/provider/schema.go @@ -17,14 +17,19 @@ package provider import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/provider/schema" "pgregory.net/rapid" ) -const tfIdentifierRegexp = "[a-z_][a-z_0-9]*" -const defaultDepth = 3 +const ( + tfIdentifierRegexp = "[a-z_][a-z_0-9]*" + defaultDepth = 3 + maxObjectSize = 4 +) -func Schema() *rapid.Generator[schema.Schema] { +func Schema(ctx context.Context) *rapid.Generator[schema.Schema] { return rapid.Custom(func(t *rapid.T) schema.Schema { // We need to generate a set of attributes and blocks, all with non-overlapping names. names := attrAndBlockNames().Draw(t, "names") @@ -36,7 +41,7 @@ func Schema() *rapid.Generator[schema.Schema] { DeprecationMessage: rapid.String().Draw(t, "deprecation message"), } - if diags := s.Validate(); diags.HasError() { + if diags := s.ValidateImplementation(ctx); diags.HasError() { t.Fatalf("Invalid schema generated: %#v", diags) } @@ -46,7 +51,12 @@ func Schema() *rapid.Generator[schema.Schema] { func attrAndBlockNames() *rapid.Generator[struct{ attr, block []string }] { return rapid.Custom(func(t *rapid.T) struct{ attr, block []string } { - attrAndBlockNames := rapid.SliceOfDistinct(rapid.StringMatching(tfIdentifierRegexp), rapid.ID).Draw(t, "names") + attrAndBlockNames := rapid.SliceOfNDistinct( + rapid.StringMatching(tfIdentifierRegexp), + -1, + maxObjectSize, + rapid.ID, + ).Draw(t, "names") split := rapid.IntRange(0, len(attrAndBlockNames)).Draw(t, "attr block split") attrNames, blockNames := attrAndBlockNames[:split], attrAndBlockNames[split:] return struct{ attr, block []string }{attrNames, blockNames} @@ -348,9 +358,10 @@ func nestedAttributeObject(depth int) *rapid.Generator[schema.NestedAttributeObj return rapid.Custom(func(t *rapid.T) schema.NestedAttributeObject { return schema.NestedAttributeObject{ - Attributes: rapid.MapOf( + Attributes: rapid.MapOfN( rapid.StringMatching(tfIdentifierRegexp), attribute(depth-1), + -1, maxObjectSize, ).Draw(t, "Attributes"), CustomType: nil, // We are omitting custom types for now. Validators: nil, // We are omitting validators here