@@ -50,10 +50,13 @@ import (
5050// }
5151//
5252// For details on the test itself, see [Configure].
53- func MakeConfigure (schema schema.Schema , tfConfig map [string ]cty.Value , puConfig resource.PropertyMap ) func (t * testing.T ) {
53+ func MakeConfigure (
54+ schema schema.Schema , tfConfig map [string ]cty.Value , puConfig resource.PropertyMap ,
55+ options ... ConfigureOption ,
56+ ) func (t * testing.T ) {
5457 return func (t * testing.T ) {
5558 t .Parallel ()
56- Configure (t , schema , tfConfig , puConfig )
59+ Configure (t , schema , tfConfig , puConfig , options ... )
5760 }
5861}
5962
@@ -81,9 +84,17 @@ func MakeConfigure(schema schema.Schema, tfConfig map[string]cty.Value, puConfig
8184// +--------------------+ +---------------------+
8285//
8386// Configure should be safe to run in parallel.
84- func Configure (t * testing.T , schema schema.Schema , tfConfig map [string ]cty.Value , puConfig resource.PropertyMap ) {
87+ func Configure (
88+ t TestingT , schema schema.Schema , tfConfig map [string ]cty.Value , puConfig resource.PropertyMap ,
89+ options ... ConfigureOption ,
90+ ) {
8591 skipUnlessLinux (t )
8692
93+ var opts configureOptions
94+ for _ , o := range options {
95+ o (& opts )
96+ }
97+
8798 // By default, logs only show when they are on a failed test. By logging to
8899 // topLevelT, we can log items to be shown if downstream tests fail.
89100 topLevelT := t
@@ -103,8 +114,8 @@ func Configure(t *testing.T, schema schema.Schema, tfConfig map[string]cty.Value
103114 }
104115
105116 var tfOutput , puOutput tfsdk.Config
106- t . Run ( "tf" , func ( t * testing. T ) {
107- defer propageteSkip ( topLevelT , t )
117+
118+ withAugment ( t , func ( t augmentedT ) { // --- Run Terraform Provider ---
108119 var hcl bytes.Buffer
109120 err := crosstests .WritePF (& hcl ).Provider (schema , providerName , tfConfig )
110121 require .NoError (t , err )
@@ -120,13 +131,12 @@ resource "` + providerName + `_res" "res" {}
120131
121132 driver .Write (t , hcl .String ())
122133 plan , err := driver .Plan (t )
123- require .NoError (t , err )
134+ require .NoError (t , err , "failed to generate TF plan" )
124135 err = driver .Apply (t , plan )
125136 require .NoError (t , err )
126137 })
127138
128- t .Run ("bridged" , func (t * testing.T ) {
129- defer propageteSkip (topLevelT , t )
139+ withAugment (t , func (t augmentedT ) { // --- Run Pulumi Provider ---
130140 dir := t .TempDir ()
131141
132142 pulumiYaml := map [string ]any {
@@ -187,11 +197,20 @@ resource "` + providerName + `_res" "res" {}
187197 contract .Ignore (test .Up (t )) // Assert that the update succeeded, but not the result.
188198 })
189199
190- skipCompare := t .Failed () || t .Skipped ()
191- t .Run ("compare" , func (t * testing.T ) {
192- if skipCompare {
193- t .Skipf ("skipping since earlier steps did not complete" )
194- }
200+ // --- Compare results -----------------------------
201+ if opts .testEqual != nil {
202+ opts .testEqual (t , tfOutput , puOutput )
203+ } else {
195204 assert .Equal (t , tfOutput , puOutput )
196- })
205+ }
206+ }
207+
208+ type ConfigureOption func (* configureOptions )
209+
210+ type configureOptions struct {
211+ testEqual func (t TestingT , tfOutput , puOutput tfsdk.Config )
212+ }
213+
214+ func WithConfigureEqual (equal func (t TestingT , tfOutput , puOutput tfsdk.Config )) ConfigureOption {
215+ return func (opts * configureOptions ) { opts .testEqual = equal }
197216}
0 commit comments