Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-tests for PF's Configure #2467

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Oct 9, 2024

The interface for configure cross-tests is:

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:

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

@iwahbe iwahbe self-assigned this Oct 9, 2024
@iwahbe iwahbe force-pushed the iwahbe/pf-configure-cross-tests branch 2 times, most recently from d02c353 to 775b13a Compare October 9, 2024 12:48
Copy link
Contributor

@VenelinMartinov VenelinMartinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding this! Out of scope here, but might be nice to add a simple resource test to make sure the library interface fits that nicely as well before adopting it more.

pf/tests/internal/cross-tests/README.md Outdated Show resolved Hide resolved
pf/tests/internal/providerbuilder/build_provider.go Outdated Show resolved Hide resolved
pf/tests/provider_configure_test.go Show resolved Hide resolved
pf/tests/provider_configure_test.go Show resolved Hide resolved
pkg/tests/cross-tests/tfwrite.go Outdated Show resolved Hide resolved
pkg/tests/cross-tests/tfwrite.go Show resolved Hide resolved
@iwahbe iwahbe force-pushed the iwahbe/pf-configure-cross-tests branch 5 times, most recently from 3063401 to daa1350 Compare October 9, 2024 14:45
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 71.15385% with 60 lines in your changes missing coverage. Please review.

Project coverage is 57.19%. Comparing base (e36cdc9) to head (f4038d0).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pf/tests/internal/cross-tests/util.go 40.90% 23 Missing and 3 partials ⚠️
pf/tests/internal/cross-tests/configure.go 80.00% 18 Missing and 3 partials ⚠️
pkg/tests/cross-tests/tfwrite.go 76.92% 11 Missing and 1 partial ⚠️
...f/tests/internal/providerbuilder/build_provider.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2467      +/-   ##
==========================================
+ Coverage   57.13%   57.19%   +0.06%     
==========================================
  Files         370      372       +2     
  Lines       51037    51243     +206     
==========================================
+ Hits        29160    29310     +150     
- Misses      20288    20336      +48     
- Partials     1589     1597       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This is a pre-requisite for #2440.
@iwahbe iwahbe force-pushed the iwahbe/pf-configure-cross-tests branch from daa1350 to f4038d0 Compare October 9, 2024 15:08
// The idea is that the "Configured Provider" should not be able to tell if it was configured
// via HCL or Pulumi YAML:
//
// +--------------------+ +---------------------+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Category theory.


func (w PFWriter) Provider(sch pfproviderschema.Schema, providerName string, config map[string]cty.Value) error {
if !cty.ObjectVal(config).IsWhollyKnown() {
return fmt.Errorf("WriteHCL cannot yet write unknowns")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely out of scope but could be very nice. It could reference some proxy resource.

@t0yv0 t0yv0 self-requested a review October 9, 2024 15:43
Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the framework bits right, not the coverage yet? If it adds coverage can you comment in-line to facilitate review? Appreciated!

Comment on lines +41 to +47
t.Run("secret-string", crosstests.MakeConfigure(
schema.Schema{Attributes: map[string]schema.Attribute{
"k": schema.StringAttribute{Optional: true},
}},
map[string]cty.Value{"k": cty.StringVal("foo")},
resource.PropertyMap{"k": resource.MakeSecret(resource.NewProperty("foo"))},
))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the framework bits right, not the coverage yet? If it adds coverage can you comment in-line to facilitate review? Appreciated!

There is some coverage here, but it is not extensive. We have coverage for:

  1. A plain string property
  2. A secret string property
  3. A plain bool property
  4. A string ("false") passed to a bool property.

A follow-up PR will add actual coverage.

@iwahbe iwahbe merged commit 1146600 into master Oct 9, 2024
17 checks passed
@iwahbe iwahbe deleted the iwahbe/pf-configure-cross-tests branch October 9, 2024 15:47
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.92.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants