Skip to content

Commit bcad849

Browse files
Add resource info override options to SDKv2 Diff cross-tests (#3111)
This adds the ability to override the Resource Info for Diff cross-tests.
1 parent 24e7ac3 commit bcad849

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pkg/internal/tests/cross-tests/diff.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import (
55
"github.com/zclconf/go-cty/cty"
66

77
crosstestsimpl "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl"
8+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
89
)
910

1011
type diffOpts struct {
1112
deleteBeforeReplace bool
1213
resource2 *schema.Resource
1314
skipDiffEquivalenceCheck bool
15+
resourceInfo *info.Resource
16+
resourceInfo2Override *info.Resource
1417
}
1518

1619
// An option that can be used to customize [Diff].
@@ -31,6 +34,16 @@ func DiffSkipDiffEquivalenceCheck() DiffOption {
3134
return func(o *diffOpts) { o.skipDiffEquivalenceCheck = true }
3235
}
3336

37+
// DiffResourceInfo specifies the resource info to use for the diff.
38+
func DiffResourceInfo(resourceInfo *info.Resource) DiffOption {
39+
return func(o *diffOpts) { o.resourceInfo = resourceInfo }
40+
}
41+
42+
// DiffResourceInfo2Override specifies an optional override for the resource info to use for the second provider.
43+
func DiffResourceInfo2Override(resourceInfo *info.Resource) DiffOption {
44+
return func(o *diffOpts) { o.resourceInfo2Override = resourceInfo }
45+
}
46+
3447
func Diff(
3548
t T, resource *schema.Resource, config1, config2 map[string]cty.Value, opts ...DiffOption,
3649
) crosstestsimpl.DiffResult {
@@ -49,5 +62,7 @@ func Diff(
4962
DeleteBeforeReplace: o.deleteBeforeReplace,
5063
Resource2: o.resource2,
5164
SkipDiffEquivalenceCheck: o.skipDiffEquivalenceCheck,
65+
ResourceInfo: o.resourceInfo,
66+
ResourceInfo2Override: o.resourceInfo2Override,
5267
})
5368
}

pkg/internal/tests/cross-tests/diff_check.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import (
2828

2929
crosstestsimpl "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl"
3030
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck"
31+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
3132
)
3233

3334
type diffTestCase struct {
3435
// Schema for the resource to test diffing on.
35-
Resource *schema.Resource
36+
Resource *schema.Resource
37+
ResourceInfo *info.Resource
3638

3739
// Two resource configurations to simulate an Update from the desired state of Config1 to Config2.
3840
//
@@ -50,6 +52,9 @@ type diffTestCase struct {
5052
// Optional second schema to use as an upgrade test with a different schema.
5153
Resource2 *schema.Resource
5254

55+
// Optional second resource info to use as an upgrade test with a different schema.
56+
ResourceInfo2Override *info.Resource
57+
5358
// Whether to skip the diff equivalence check.
5459
SkipDiffEquivalenceCheck bool
5560
}
@@ -76,8 +81,16 @@ func runDiffCheck(t T, tc diffTestCase) crosstestsimpl.DiffResult {
7681
tfp1 := &schema.Provider{ResourcesMap: map[string]*schema.Resource{defRtype: resource1}}
7782
tfp2 := &schema.Provider{ResourcesMap: map[string]*schema.Resource{defRtype: resource2}}
7883

79-
bridgedProvider1 := pulcheck.BridgedProvider(t, defProviderShortName, tfp1)
80-
bridgedProvider2 := pulcheck.BridgedProvider(t, defProviderShortName, tfp2)
84+
resourceInfo1 := tc.ResourceInfo
85+
resourceInfo2 := tc.ResourceInfo
86+
if tc.ResourceInfo2Override != nil {
87+
resourceInfo2 = tc.ResourceInfo2Override
88+
}
89+
90+
bridgedProvider1 := pulcheck.BridgedProvider(t, defProviderShortName, tfp1,
91+
pulcheck.WithResourceInfo(map[string]*info.Resource{defRtype: resourceInfo1}))
92+
bridgedProvider2 := pulcheck.BridgedProvider(t, defProviderShortName, tfp2,
93+
pulcheck.WithResourceInfo(map[string]*info.Resource{defRtype: resourceInfo2}))
8194
if tc.DeleteBeforeReplace {
8295
bridgedProvider1.Resources[defRtype].DeleteBeforeReplace = true
8396
bridgedProvider2.Resources[defRtype].DeleteBeforeReplace = true

0 commit comments

Comments
 (0)