-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross-tests for PF's Configure (#2467)
The interface for configure cross-tests is: ```go func Configure( t *testing.T, schema schema.Schema, // The provider's schema tfConfig map[string]cty.Value, // Config values for HCL/TF puConfig resource.PropertyMap, // Config values for Pulumi YAML/Pulumi ) ``` Because the mapping between `tfConfig` and `puConfig` is non-trivial, and to allow for secret injection, I have chosen to allow setting `tfConfig` and `puConfig` separately. This is a pre-requisite for #2440. --- When the underlying provider configuration doesn't match between Pulumi and TF, the error looks like this: ```go func TestFailure(t *testing.T) { crosstests.Configure(t, schema.Schema{Attributes: map[string]schema.Attribute{ "k": schema.StringAttribute{Optional: true}, }}, map[string]cty.Value{"k": cty.StringVal("foo")}, resource.PropertyMap{"k": resource.NewProperty("oo")}, ) } ``` ``` go test -test.run \^TestFailure\$ warning: resource:test_res.Docs received a non-zero custom value &{ [32] false false} that is being ignored. Plugin Framework based providers do not yet support this feature. --- FAIL: TestFailure (2.25s) configure.go:129: Pulumi.yaml: backend: url: file://./data name: project resources: p: properties: k: oo type: pulumi:providers:test runtime: yaml --- FAIL: TestFailure/compare (0.00s) configure.go:174: Error Trace: /Users/ianwahbe/go/src/github.com/pulumi/pulumi-terraform-bridge/pf/tests/internal/cross-tests/configure.go:174 Error: Not equal: expected: tfsdk.Config{Raw:tftypes.Value{typ:tftypes.Object{AttributeTypes:map[string]tftypes.Type{"k":tftypes.primitive{name:"String", _:[]struct {}(nil)}}, OptionalAttributes:map[string]struct {}(nil), _:[]struct {}(nil)}, value:map[string]tftypes.Value{"k":tftypes.Value{typ:tftypes.primitive{name:"String", _:[]struct {}(nil)}, value:"foo"}}}, Schema:schema.Schema{Attributes:map[string]schema.Attribute{"k":schema.StringAttribute{CustomType:basetypes.StringTypable(nil), Required:false, Optional:true, Sensitive:false, Description:"", MarkdownDescription:"", DeprecationMessage:"", Validators:[]validator.String(nil)}}, Blocks:map[string]schema.Block(nil), Description:"", MarkdownDescription:"", DeprecationMessage:""}} actual : tfsdk.Config{Raw:tftypes.Value{typ:tftypes.Object{AttributeTypes:map[string]tftypes.Type{"k":tftypes.primitive{name:"String", _:[]struct {}(nil)}}, OptionalAttributes:map[string]struct {}(nil), _:[]struct {}(nil)}, value:map[string]tftypes.Value{"k":tftypes.Value{typ:tftypes.primitive{name:"String", _:[]struct {}(nil)}, value:"oo"}}}, Schema:schema.Schema{Attributes:map[string]schema.Attribute{"k":schema.StringAttribute{CustomType:basetypes.StringTypable(nil), Required:false, Optional:true, Sensitive:false, Description:"", MarkdownDescription:"", DeprecationMessage:"", Validators:[]validator.String(nil)}}, Blocks:map[string]schema.Block(nil), Description:"", MarkdownDescription:"", DeprecationMessage:""}} Diff: --- Expected +++ Actual @@ -18,3 +18,3 @@ }, - value: (string) (len=3) "foo" + value: (string) (len=2) "oo" } Test: TestFailure/compare FAIL exit status 1 FAIL github.com/pulumi/pulumi-terraform-bridge/pf/tests 3.059s ```
- Loading branch information
Showing
11 changed files
with
774 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Cross-tests for PF | ||
|
||
This package provides [cross-testing](../../../../pkg/tests/cross-tests/README.md) for [Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework) based Terraform | ||
providers, bridged into Pulumi with [pf](../../../README.md). | ||
|
||
It *does not* contain cross-tests. It just provides a library for writing cross-tests. | ||
|
||
An example usage looks like this: | ||
|
||
``` go | ||
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) | | ||
+--------------------+ +---------------------+ | ||
``` | ||
|
Oops, something went wrong.