11package tests
22
33import (
4- "strings"
54 "testing"
65
76 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8- "github.com/hexops/autogold/v2"
97 "github.com/zclconf/go-cty/cty"
10-
11- crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests"
128)
139
1410func TestSDKv2DetailedDiffString (t * testing.T ) {
@@ -18,28 +14,7 @@ func TestSDKv2DetailedDiffString(t *testing.T) {
1814 schemaValueMakerPairs , scenarios := generateBaseTests (
1915 schema .TypeString , cty .StringVal , "val1" , "val2" , "computed" , "default" , nilVal )
2016
21- for _ , schemaValueMakerPair := range schemaValueMakerPairs {
22- t .Run (schemaValueMakerPair .name , func (t * testing.T ) {
23- t .Parallel ()
24- for _ , scenario := range scenarios {
25- t .Run (scenario .name , func (t * testing.T ) {
26- if strings .Contains (schemaValueMakerPair .name , "required" ) &&
27- (scenario .initialValue == nil || scenario .changeValue == nil ) {
28- t .Skip ("Required fields cannot be unset" )
29- }
30- t .Parallel ()
31- diff := crosstests .Diff (t , & schemaValueMakerPair .schema , schemaValueMakerPair .valueMaker (scenario .initialValue ), schemaValueMakerPair .valueMaker (scenario .changeValue ))
32- autogold .ExpectFile (t , testOutput {
33- initialValue : scenario .initialValue ,
34- changeValue : scenario .changeValue ,
35- tfOut : diff .TFOut ,
36- pulumiOut : diff .PulumiOut ,
37- detailedDiff : diff .PulumiDiff .DetailedDiff ,
38- })
39- })
40- }
41- })
42- }
17+ runSDKv2TestMatrix (t , schemaValueMakerPairs , scenarios )
4318}
4419
4520func TestSDKv2DetailedDiffBool (t * testing.T ) {
@@ -49,28 +24,7 @@ func TestSDKv2DetailedDiffBool(t *testing.T) {
4924 schemaValueMakerPairs , scenarios := generateBaseTests (
5025 schema .TypeBool , cty .BoolVal , true , false , true , false , nilVal )
5126
52- for _ , schemaValueMakerPair := range schemaValueMakerPairs {
53- t .Run (schemaValueMakerPair .name , func (t * testing.T ) {
54- t .Parallel ()
55- for _ , scenario := range scenarios {
56- t .Run (scenario .name , func (t * testing.T ) {
57- if strings .Contains (schemaValueMakerPair .name , "required" ) &&
58- (scenario .initialValue == nil || scenario .changeValue == nil ) {
59- t .Skip ("Required fields cannot be unset" )
60- }
61- t .Parallel ()
62- diff := crosstests .Diff (t , & schemaValueMakerPair .schema , schemaValueMakerPair .valueMaker (scenario .initialValue ), schemaValueMakerPair .valueMaker (scenario .changeValue ))
63- autogold .ExpectFile (t , testOutput {
64- initialValue : scenario .initialValue ,
65- changeValue : scenario .changeValue ,
66- tfOut : diff .TFOut ,
67- pulumiOut : diff .PulumiOut ,
68- detailedDiff : diff .PulumiDiff .DetailedDiff ,
69- })
70- })
71- }
72- })
73- }
27+ runSDKv2TestMatrix (t , schemaValueMakerPairs , scenarios )
7428}
7529
7630func TestSDKv2DetailedDiffInt (t * testing.T ) {
@@ -80,28 +34,7 @@ func TestSDKv2DetailedDiffInt(t *testing.T) {
8034 schemaValueMakerPairs , scenarios := generateBaseTests (
8135 schema .TypeInt , cty .NumberIntVal , 1 , 2 , 3 , 4 , nilVal )
8236
83- for _ , schemaValueMakerPair := range schemaValueMakerPairs {
84- t .Run (schemaValueMakerPair .name , func (t * testing.T ) {
85- t .Parallel ()
86- for _ , scenario := range scenarios {
87- t .Run (scenario .name , func (t * testing.T ) {
88- if strings .Contains (schemaValueMakerPair .name , "required" ) &&
89- (scenario .initialValue == nil || scenario .changeValue == nil ) {
90- t .Skip ("Required fields cannot be unset" )
91- }
92- t .Parallel ()
93- diff := crosstests .Diff (t , & schemaValueMakerPair .schema , schemaValueMakerPair .valueMaker (scenario .initialValue ), schemaValueMakerPair .valueMaker (scenario .changeValue ))
94- autogold .ExpectFile (t , testOutput {
95- initialValue : scenario .initialValue ,
96- changeValue : scenario .changeValue ,
97- tfOut : diff .TFOut ,
98- pulumiOut : diff .PulumiOut ,
99- detailedDiff : diff .PulumiDiff .DetailedDiff ,
100- })
101- })
102- }
103- })
104- }
37+ runSDKv2TestMatrix (t , schemaValueMakerPairs , scenarios )
10538}
10639
10740func TestSDKv2DetailedDiffFloat (t * testing.T ) {
@@ -111,26 +44,5 @@ func TestSDKv2DetailedDiffFloat(t *testing.T) {
11144 schemaValueMakerPairs , scenarios := generateBaseTests (
11245 schema .TypeFloat , cty .NumberFloatVal , 1.0 , 2.0 , 3.0 , 4.0 , nilVal )
11346
114- for _ , schemaValueMakerPair := range schemaValueMakerPairs {
115- t .Run (schemaValueMakerPair .name , func (t * testing.T ) {
116- t .Parallel ()
117- for _ , scenario := range scenarios {
118- t .Run (scenario .name , func (t * testing.T ) {
119- if strings .Contains (schemaValueMakerPair .name , "required" ) &&
120- (scenario .initialValue == nil || scenario .changeValue == nil ) {
121- t .Skip ("Required fields cannot be unset" )
122- }
123- t .Parallel ()
124- diff := crosstests .Diff (t , & schemaValueMakerPair .schema , schemaValueMakerPair .valueMaker (scenario .initialValue ), schemaValueMakerPair .valueMaker (scenario .changeValue ))
125- autogold .ExpectFile (t , testOutput {
126- initialValue : scenario .initialValue ,
127- changeValue : scenario .changeValue ,
128- tfOut : diff .TFOut ,
129- pulumiOut : diff .PulumiOut ,
130- detailedDiff : diff .PulumiDiff .DetailedDiff ,
131- })
132- })
133- }
134- })
135- }
47+ runSDKv2TestMatrix (t , schemaValueMakerPairs , scenarios )
13648}
0 commit comments