@@ -50,10 +50,13 @@ import (
50
50
// }
51
51
//
52
52
// 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 ) {
54
57
return func (t * testing.T ) {
55
58
t .Parallel ()
56
- Configure (t , schema , tfConfig , puConfig )
59
+ Configure (t , schema , tfConfig , puConfig , options ... )
57
60
}
58
61
}
59
62
@@ -81,9 +84,17 @@ func MakeConfigure(schema schema.Schema, tfConfig map[string]cty.Value, puConfig
81
84
// +--------------------+ +---------------------+
82
85
//
83
86
// 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
+ ) {
85
91
skipUnlessLinux (t )
86
92
93
+ var opts configureOptions
94
+ for _ , o := range options {
95
+ o (& opts )
96
+ }
97
+
87
98
// By default, logs only show when they are on a failed test. By logging to
88
99
// topLevelT, we can log items to be shown if downstream tests fail.
89
100
topLevelT := t
@@ -103,8 +114,8 @@ func Configure(t *testing.T, schema schema.Schema, tfConfig map[string]cty.Value
103
114
}
104
115
105
116
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 ---
108
119
var hcl bytes.Buffer
109
120
err := crosstests .WritePF (& hcl ).Provider (schema , providerName , tfConfig )
110
121
require .NoError (t , err )
@@ -120,13 +131,12 @@ resource "` + providerName + `_res" "res" {}
120
131
121
132
driver .Write (t , hcl .String ())
122
133
plan , err := driver .Plan (t )
123
- require .NoError (t , err )
134
+ require .NoError (t , err , "failed to generate TF plan" )
124
135
err = driver .Apply (t , plan )
125
136
require .NoError (t , err )
126
137
})
127
138
128
- t .Run ("bridged" , func (t * testing.T ) {
129
- defer propageteSkip (topLevelT , t )
139
+ withAugment (t , func (t augmentedT ) { // --- Run Pulumi Provider ---
130
140
dir := t .TempDir ()
131
141
132
142
pulumiYaml := map [string ]any {
@@ -187,11 +197,20 @@ resource "` + providerName + `_res" "res" {}
187
197
contract .Ignore (test .Up (t )) // Assert that the update succeeded, but not the result.
188
198
})
189
199
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 {
195
204
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 }
197
216
}
0 commit comments