crosstests

package
v3.98.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

README

Cross-tests for PF

This package provides cross-testing for Plugin Framework based Terraform providers, bridged into Pulumi with pf.

It does not contain cross-tests. It just provides a library for writing cross-tests.

An example usage looks like this:

func TestConfigure(t *testing.T) {
	t.Parallel()

    schema := schema.Schema{Attributes: map[string]schema.Attribute{
		"k": schema.StringAttribute{Optional: true},
	}}

    tfInput := map[string]cty.Value{"k": cty.StringVal("foo")}

    puInput := resource.PropertyMap{"k": resource.MakeSecret(resource.NewProperty("foo"))}

	crosstests.Configure(schema, tfInput, puInput)
}

Here, the cross-test will assert that a provider whose configuration is described by schema will observe the same inputs when configured in via HCL with the inputs tfInputs and when bridged and configured with Pulumi and puInputs.

The idea is that the "Configured Provider" should not be able to tell if it was configured via HCL or Pulumi YAML:

    +--------------------+                      +---------------------+
    | Terraform Provider |--------------------->| Configure(tfInputs) |
    +--------------------+                      +---------------------+
              |                                                        \
              |                                                         \
              |                                                          \
              |                                                      +---------------------+
              | tfbridge.ShimProvider                                | Configured Provider |
              |                                                      +---------------------+
              |                                                          /
              |                                                         /
              V                                                        /
    +--------------------+                      +---------------------+
    |   Pulumi Provider  |--------------------->| Configure(puInputs) |
    +--------------------+                      +---------------------+

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(t T, schema pschema.Schema, tfConfig map[string]cty.Value, options ...ConfigureOption)

Configure will assert that a provider who's configuration is described by schema will observe the same inputs when configured in via HCL with the inputs tfInputs and when bridged and configured with Pulumi and puInputs.

The idea is that the "Configured Provider" should not be able to tell if it was configured via HCL or Pulumi YAML:

+--------------------+                      +---------------------+
| Terraform Provider |--------------------->| Configure(tfInputs) |
+--------------------+                      +---------------------+
          |                                                        \
          |                                                         \
          |                                                          \
          |                                                      +---------------------+
          | tfbridge.ShimProvider                                | Configured Provider |
          |                                                      +---------------------+
          |                                                          /
          |                                                         /
          V                                                        /
+--------------------+                      +---------------------+
|   Pulumi Provider  |--------------------->| Configure(puInputs) |
+--------------------+                      +---------------------+

Configure should be safe to run in parallel.

func Diff added in v3.95.0

func Diff(t T, res pb.Resource, tfConfig1, tfConfig2 map[string]cty.Value, options ...DiffOption) crosstestsimpl.DiffResult

Diff will assert that given two resource configurations, the diffs are the same when computed by Terraform and Pulumi.

Diff should be safe to run in parallel.

func MakeConfigure

func MakeConfigure(schema pschema.Schema, tfConfig map[string]cty.Value, options ...ConfigureOption) func(t *testing.T)

MakeConfigure returns a testing subtest of Configure.

func TestMyProperty(t *testing.T) {
	t.Run("my-subtest", crosstests.MakeConfigure(schema, tfConfig, puConfig))
}

For details on the test itself, see Configure.

Types

type ConfigureOption added in v3.95.0

type ConfigureOption func(*configureOpts)

func ConfigureProviderInfo added in v3.95.0

func ConfigureProviderInfo(info map[string]*info.Schema) ConfigureOption

CreateResourceInfo specifies a map of info.Schema to apply to the provider under test.

func ConfigurePulumiConfig added in v3.95.0

func ConfigurePulumiConfig(config resource.PropertyMap) ConfigureOption

ConfigurePulumiConfig specifies an explicit pulumi value for the configure call.

type DiffOption added in v3.95.0

type DiffOption func(*diffOpts)

func DiffProviderInfo added in v3.95.0

func DiffProviderInfo(info map[string]*info.Schema) DiffOption

DiffProviderInfo specifies a map of info.Schema to apply to the provider under test.

type T added in v3.95.0

type T = crosstestsimpl.T

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL