diff --git a/pf/go.mod b/pf/go.mod index 79c9aef97..ea35902ae 100644 --- a/pf/go.mod +++ b/pf/go.mod @@ -16,7 +16,6 @@ require ( github.com/hashicorp/terraform-plugin-go v0.22.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/pulumi/providertest v0.0.11 github.com/pulumi/pulumi-terraform-bridge/v3 v3.86.0 github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8 github.com/stretchr/testify v1.9.0 diff --git a/pf/tfbridge/tests/provider_test.go b/pf/tfbridge/tests/provider_test.go deleted file mode 100644 index a6d942574..000000000 --- a/pf/tfbridge/tests/provider_test.go +++ /dev/null @@ -1,181 +0,0 @@ -package tfbridgetests - -import ( - "context" - "encoding/json" - "io" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/pulumi/providertest/replay" - "github.com/pulumi/pulumi/sdk/v3/go/common/diag" - "github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors" - "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" - pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" - - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" - shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" -) - -// Demonstrating the use of the newTestProvider helper. -func TestWithNewTestProvider(t *testing.T) { - ctx := context.Background() - p := newTestProvider(ctx, tfbridge.ProviderInfo{ - P: shimv2.NewProvider(&schema.Provider{ - Schema: map[string]*schema.Schema{}, - ResourcesMap: map[string]*schema.Resource{ - "example_resource": { - Schema: map[string]*schema.Schema{ - "array_property_values": { - Type: schema.TypeList, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Optional: true, - }, - }, - }, - }, - }), - Name: "testprov", - ResourcePrefix: "example", - Resources: map[string]*tfbridge.ResourceInfo{ - "example_resource": {Tok: "testprov:index:ExampleResource"}, - }, - }, newTestProviderOptions{}) - - replay.Replay(t, p, ` - { - "method": "/pulumirpc.ResourceProvider/Check", - "request": { - "urn": "urn:pulumi:dev::teststack::testprov:index:ExampleResource::exres", - "randomSeed": "ZCiVOcvG/CT5jx4XriguWgj2iMpQEb8P3ZLqU/AS2yg=", - "olds": { - "__defaults": [] - }, - "news": { - "arrayPropertyValues": [] - } - }, - "response": { - "inputs": { - "__defaults": [], - "arrayPropertyValues": [] - } - } - } - `) -} - -func TestValidateInputs(t *testing.T) { - ctx := context.Background() - os.Setenv("PULUMI_ERROR_TYPE_CHECKER", "true") - p := newTestProvider(ctx, tfbridge.ProviderInfo{ - P: shimv2.NewProvider(&schema.Provider{ - Schema: map[string]*schema.Schema{}, - ResourcesMap: map[string]*schema.Resource{ - "example_resource": { - Schema: map[string]*schema.Schema{ - "map_property_values": { - Type: schema.TypeMap, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Optional: true, - }, - "string_array_property_values": { - Type: schema.TypeList, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Optional: true, - }, - "bool_property_values": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - }), - Name: "testprov", - ResourcePrefix: "example", - Resources: map[string]*tfbridge.ResourceInfo{ - "example_resource": {Tok: "testprov:index:ExampleResource"}, - }, - }, newTestProviderOptions{}) - - // stringArrayPropertyValues is a test that ensures - // that we don't fail on values that can be converted. i.e. 1 -> "1" - replay.Replay(t, p, ` - { - "method": "/pulumirpc.ResourceProvider/Check", - "request": { - "urn": "urn:pulumi:dev::teststack::testprov:index:ExampleResource::exres", - "randomSeed": "ZCiVOcvG/CT5jx4XriguWgj2iMpQEb8P3ZLqU/AS2yg=", - "olds": { - "__defaults": [] - }, - "news": { - "stringArrayPropertyValues": [1, "1"], - "mapPropertyValues": [{"foo": "bar"}], - "boolPropertyValues": true - } - }, - "response": { - "failures": [ - {"reason": "expected object type, got [] type. Examine values at 'exres.mapPropertyValues'."} - ], - "inputs": { - "__defaults": [], - "stringArrayPropertyValues": ["1", "1"], - "boolPropertyValues": true, - "mapPropertyValues": [ - {"foo": "bar"} - ] - } - } - } - `) -} - -func nilSink() diag.Sink { - nilSink := diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ - Color: colors.Never, - }) - return nilSink -} - -// Variation of NewProvider to facilitate white-box testing. -func newTestProvider( - ctx context.Context, - info tfbridge.ProviderInfo, - opts newTestProviderOptions, -) pulumirpc.ResourceProviderServer { - if opts.version == "" { - opts.version = "0.0.1" - } - if opts.module == "" { - opts.module = "testprovier" - } - - var schemaBytes []byte - - if !opts.noSchema { - packageSpec, err := tfgen.GenerateSchema(info, nilSink()) - contract.AssertNoErrorf(err, "Failed to generate a schema for the test provider") - bytes, err := json.Marshal(packageSpec) - contract.AssertNoErrorf(err, "Failed to marshal a schema for the test provider") - schemaBytes = bytes - } - - return tfbridge.NewProvider(ctx, nil, opts.module, opts.version, info.P, info, schemaBytes) -} - -type newTestProviderOptions struct { - module string - version string - noSchema bool -}