Skip to content

Commit f800d2d

Browse files
recordings
1 parent 861ec1f commit f800d2d

File tree

754 files changed

+8788
-8130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

754 files changed

+8788
-8130
lines changed

pkg/tests/diff_test/detailed_diff_list_test.go

Lines changed: 35 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import (
55
"testing"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
"github.com/hexops/autogold/v2"
9-
"github.com/zclconf/go-cty/cty"
10-
11-
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests"
128
)
139

1410
func TestSDKv2DetailedDiffList(t *testing.T) {
1511
t.Parallel()
1612

1713
listAttrSchema := schema.Resource{
1814
Schema: map[string]*schema.Schema{
19-
"list_attr": {
15+
"prop": {
2016
Type: schema.TypeList,
2117
Optional: true,
2218
Elem: &schema.Schema{Type: schema.TypeString},
@@ -26,7 +22,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
2622

2723
listAttrSchemaForceNew := schema.Resource{
2824
Schema: map[string]*schema.Schema{
29-
"list_attr": {
25+
"prop": {
3026
Type: schema.TypeList,
3127
Optional: true,
3228
Elem: &schema.Schema{Type: schema.TypeString},
@@ -37,7 +33,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
3733

3834
maxItemsOneAttrSchema := schema.Resource{
3935
Schema: map[string]*schema.Schema{
40-
"list_attr": {
36+
"prop": {
4137
Type: schema.TypeList,
4238
Optional: true,
4339
MaxItems: 1,
@@ -48,7 +44,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
4844

4945
maxItemsOneAttrSchemaForceNew := schema.Resource{
5046
Schema: map[string]*schema.Schema{
51-
"list_attr": {
47+
"prop": {
5248
Type: schema.TypeList,
5349
Optional: true,
5450
MaxItems: 1,
@@ -60,12 +56,12 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
6056

6157
listBlockSchema := schema.Resource{
6258
Schema: map[string]*schema.Schema{
63-
"list_block": {
59+
"prop": {
6460
Type: schema.TypeList,
6561
Optional: true,
6662
Elem: &schema.Resource{
6763
Schema: map[string]*schema.Schema{
68-
"prop": {
64+
"nested_prop": {
6965
Type: schema.TypeString,
7066
Optional: true,
7167
},
@@ -77,13 +73,13 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
7773

7874
listBlockSchemaForceNew := schema.Resource{
7975
Schema: map[string]*schema.Schema{
80-
"list_block": {
76+
"prop": {
8177
Type: schema.TypeList,
8278
Optional: true,
8379
ForceNew: true,
8480
Elem: &schema.Resource{
8581
Schema: map[string]*schema.Schema{
86-
"prop": {
82+
"nested_prop": {
8783
Type: schema.TypeString,
8884
Optional: true,
8985
},
@@ -95,7 +91,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
9591

9692
listBlockSchemaNestedForceNew := schema.Resource{
9793
Schema: map[string]*schema.Schema{
98-
"list_block": {
94+
"prop": {
9995
Type: schema.TypeList,
10096
Optional: true,
10197
Elem: &schema.Resource{
@@ -113,7 +109,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
113109

114110
maxItemsOneBlockSchema := schema.Resource{
115111
Schema: map[string]*schema.Schema{
116-
"list_block": {
112+
"prop": {
117113
Type: schema.TypeList,
118114
Optional: true,
119115
MaxItems: 1,
@@ -131,7 +127,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
131127

132128
maxItemsOneBlockSchemaForceNew := schema.Resource{
133129
Schema: map[string]*schema.Schema{
134-
"list_block": {
130+
"prop": {
135131
Type: schema.TypeList,
136132
Optional: true,
137133
MaxItems: 1,
@@ -150,7 +146,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
150146

151147
maxItemsOneBlockSchemaNestedForceNew := schema.Resource{
152148
Schema: map[string]*schema.Schema{
153-
"list_block": {
149+
"prop": {
154150
Type: schema.TypeList,
155151
Optional: true,
156152
MaxItems: 1,
@@ -169,7 +165,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
169165

170166
listBlockSchemaSensitive := schema.Resource{
171167
Schema: map[string]*schema.Schema{
172-
"list_block": {
168+
"prop": {
173169
Type: schema.TypeList,
174170
Optional: true,
175171
Sensitive: true,
@@ -187,7 +183,7 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
187183

188184
listBlockSchemaNestedSensitive := schema.Resource{
189185
Schema: map[string]*schema.Schema{
190-
"list_block": {
186+
"prop": {
191187
Type: schema.TypeList,
192188
Optional: true,
193189
Elem: &schema.Resource{
@@ -203,97 +199,25 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
203199
},
204200
}
205201

206-
attrList := func(arr *[]string) map[string]cty.Value {
207-
if arr == nil {
208-
return map[string]cty.Value{}
209-
}
210-
211-
if len(*arr) == 0 {
212-
return map[string]cty.Value{
213-
"list_attr": cty.ListValEmpty(cty.String),
214-
}
215-
}
216-
217-
slice := make([]cty.Value, len(*arr))
218-
for i, v := range *arr {
219-
slice[i] = cty.StringVal(v)
220-
}
221-
return map[string]cty.Value{
222-
"list_attr": cty.ListVal(slice),
223-
}
224-
}
225-
226-
blockList := func(arr *[]string) map[string]cty.Value {
227-
if arr == nil {
228-
return map[string]cty.Value{}
229-
}
230-
231-
if len(*arr) == 0 {
232-
return map[string]cty.Value{
233-
"list_block": cty.ListValEmpty(cty.DynamicPseudoType),
234-
}
235-
}
236-
237-
slice := make([]cty.Value, len(*arr))
238-
for i, v := range *arr {
239-
slice[i] = cty.ObjectVal(map[string]cty.Value{"prop": cty.StringVal(v)})
240-
}
241-
return map[string]cty.Value{
242-
"list_block": cty.ListVal(slice),
243-
}
244-
}
245-
246-
nestedBlockList := func(arr *[]string) map[string]cty.Value {
247-
if arr == nil {
248-
return map[string]cty.Value{}
249-
}
250-
251-
if len(*arr) == 0 {
252-
return map[string]cty.Value{
253-
"list_block": cty.ListValEmpty(cty.DynamicPseudoType),
254-
}
255-
}
256-
257-
slice := make([]cty.Value, len(*arr))
258-
for i, v := range *arr {
259-
slice[i] = cty.ObjectVal(map[string]cty.Value{"nested_prop": cty.StringVal(v)})
260-
}
261-
return map[string]cty.Value{
262-
"list_block": cty.ListVal(slice),
263-
}
264-
}
265-
266-
listPairs := []struct {
267-
name string
268-
schema schema.Resource
269-
valueMaker func(*[]string) map[string]cty.Value
270-
}{
271-
{"list attribute", listAttrSchema, attrList},
272-
{"list attribute force new", listAttrSchemaForceNew, attrList},
273-
{"list block", listBlockSchema, blockList},
274-
{"list block force new", listBlockSchemaForceNew, blockList},
275-
{"list block nested force new", listBlockSchemaNestedForceNew, blockList},
276-
{"list block sensitive", listBlockSchemaSensitive, blockList},
277-
{"list block nested sensitive", listBlockSchemaNestedSensitive, nestedBlockList},
202+
listPairs := []diffSchemaValueMakerPair[[]string]{
203+
{"list attribute", listAttrSchema, listValueMaker},
204+
{"list attribute force new", listAttrSchemaForceNew, listValueMaker},
205+
{"list block", listBlockSchema, nestedListValueMaker},
206+
{"list block force new", listBlockSchemaForceNew, nestedListValueMaker},
207+
{"list block nested force new", listBlockSchemaNestedForceNew, nestedListValueMaker},
208+
{"list block sensitive", listBlockSchemaSensitive, nestedListValueMaker},
209+
{"list block nested sensitive", listBlockSchemaNestedSensitive, nestedListValueMaker},
278210
}
279211

280-
maxItemsOnePairs := []struct {
281-
name string
282-
schema schema.Resource
283-
valueMaker func(*[]string) map[string]cty.Value
284-
}{
285-
{"max items one attribute", maxItemsOneAttrSchema, attrList},
286-
{"max items one attribute force new", maxItemsOneAttrSchemaForceNew, attrList},
287-
{"max items one block", maxItemsOneBlockSchema, nestedBlockList},
288-
{"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedBlockList},
289-
{"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedBlockList},
212+
maxItemsOnePairs := []diffSchemaValueMakerPair[[]string]{
213+
{"max items one attribute", maxItemsOneAttrSchema, listValueMaker},
214+
{"max items one attribute force new", maxItemsOneAttrSchemaForceNew, listValueMaker},
215+
{"max items one block", maxItemsOneBlockSchema, nestedListValueMaker},
216+
{"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedListValueMaker},
217+
{"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedListValueMaker},
290218
}
291219

292-
oneElementScenarios := []struct {
293-
name string
294-
initialValue *[]string
295-
changeValue *[]string
296-
}{
220+
oneElementScenarios := []diffScenario[[]string]{
297221
{"unchanged empty", nil, nil},
298222
{"unchanged non-empty", ref([]string{"val1"}), ref([]string{"val1"})},
299223
{"added non-empty", nil, ref([]string{"val1"})},
@@ -311,17 +235,13 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
311235
longListAddedBack = append(longListAddedBack, "value20")
312236
longListAddedFront := append([]string{"value20"}, *longList...)
313237

314-
multiElementScenarios := []struct {
315-
name string
316-
initialValue *[]string
317-
changeValue *[]string
318-
}{
238+
multiElementScenarios := []diffScenario[[]string]{
319239
{"list element added front", ref([]string{"val2", "val3"}), ref([]string{"val1", "val2", "val3"})},
320240
{"list element added back", ref([]string{"val1", "val2"}), ref([]string{"val1", "val2", "val3"})},
321241
{"list element added middle", ref([]string{"val1", "val3"}), ref([]string{"val1", "val2", "val3"})},
322-
{"list element removed front", ref([]string{"val1", "val2", "val3"}), ref([]string{"val3", "val2"})},
323-
{"list element removed middle", ref([]string{"val1", "val2", "val3"}), ref([]string{"val3", "val1"})},
324-
{"list element removed end", ref([]string{"val1", "val2", "val3"}), ref([]string{"val2", "val1"})},
242+
{"list element removed front", ref([]string{"val1", "val2", "val3"}), ref([]string{"val2", "val3"})},
243+
{"list element removed middle", ref([]string{"val1", "val2", "val3"}), ref([]string{"val1", "val3"})},
244+
{"list element removed end", ref([]string{"val1", "val2", "val3"}), ref([]string{"val1", "val2"})},
325245
{"one added, one removed", ref([]string{"val1", "val2", "val3"}), ref([]string{"val2", "val3", "val4"})},
326246
{"long list added back", longList, &longListAddedBack},
327247
// TODO[pulumi/pulumi-terraform-bridge#2239]: These cases present as multiple changes instead of just one
@@ -332,38 +252,6 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
332252

333253
scenarios := append(oneElementScenarios, multiElementScenarios...)
334254

335-
runTest := func(t *testing.T, schema schema.Resource, valueMaker func(*[]string) map[string]cty.Value, initialValue *[]string, changeValue *[]string) {
336-
diff := crosstests.Diff(t, &schema, valueMaker(initialValue), valueMaker(changeValue))
337-
autogold.ExpectFile(t, testOutput{
338-
initialValue: initialValue,
339-
changeValue: changeValue,
340-
tfOut: diff.TFOut,
341-
pulumiOut: diff.PulumiOut,
342-
detailedDiff: diff.PulumiDiff.DetailedDiff,
343-
})
344-
}
345-
346-
for _, schemaValueMakerPair := range listPairs {
347-
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
348-
t.Parallel()
349-
for _, scenario := range scenarios {
350-
t.Run(scenario.name, func(t *testing.T) {
351-
t.Parallel()
352-
runTest(t, schemaValueMakerPair.schema, schemaValueMakerPair.valueMaker, scenario.initialValue, scenario.changeValue)
353-
})
354-
}
355-
})
356-
}
357-
358-
for _, schemaValueMakerPair := range maxItemsOnePairs {
359-
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
360-
t.Parallel()
361-
for _, scenario := range oneElementScenarios {
362-
t.Run(scenario.name, func(t *testing.T) {
363-
t.Parallel()
364-
runTest(t, schemaValueMakerPair.schema, schemaValueMakerPair.valueMaker, scenario.initialValue, scenario.changeValue)
365-
})
366-
}
367-
})
368-
}
255+
runSDKv2TestMatrix(t, listPairs, scenarios)
256+
runSDKv2TestMatrix(t, maxItemsOnePairs, oneElementScenarios)
369257
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffList/list_attribute/added_non-empty.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Terraform will perform the following actions:
1111

1212
# crossprovider_test_res.example will be updated in-place
1313
~ resource "crossprovider_test_res" "example" {
14-
id = "newid"
15-
+ list_attr = [
14+
id = "newid"
15+
+ prop = [
1616
+ "val1",
1717
]
1818
}
@@ -26,12 +26,12 @@ Plan: 0 to add, 1 to change, 0 to destroy.
2626
~ crossprovider:index/testRes:TestRes: (update)
2727
[id=newid]
2828
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
29-
+ listAttrs: [
29+
+ props: [
3030
+ [0]: "val1"
3131
]
3232
Resources:
3333
~ 1 to update
3434
1 unchanged
3535
`,
36-
detailedDiff: map[string]interface{}{"listAttrs": map[string]interface{}{}},
36+
detailedDiff: map[string]interface{}{"props": map[string]interface{}{}},
3737
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffList/list_attribute/changed.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Terraform will perform the following actions:
1212

1313
# crossprovider_test_res.example will be updated in-place
1414
~ resource "crossprovider_test_res" "example" {
15-
id = "newid"
16-
~ list_attr = [
15+
id = "newid"
16+
~ prop = [
1717
~ "val1" -> "val2",
1818
]
1919
}
@@ -27,12 +27,12 @@ Plan: 0 to add, 1 to change, 0 to destroy.
2727
~ crossprovider:index/testRes:TestRes: (update)
2828
[id=newid]
2929
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
30-
~ listAttrs: [
30+
~ props: [
3131
~ [0]: "val1" => "val2"
3232
]
3333
Resources:
3434
~ 1 to update
3535
1 unchanged
3636
`,
37-
detailedDiff: map[string]interface{}{"listAttrs[0]": map[string]interface{}{"kind": "UPDATE"}},
37+
detailedDiff: map[string]interface{}{"props[0]": map[string]interface{}{"kind": "UPDATE"}},
3838
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffList/list_attribute/list_element_added_back.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Terraform will perform the following actions:
1717

1818
# crossprovider_test_res.example will be updated in-place
1919
~ resource "crossprovider_test_res" "example" {
20-
id = "newid"
21-
~ list_attr = [
20+
id = "newid"
21+
~ prop = [
2222
# (1 unchanged element hidden)
2323
"val2",
2424
+ "val3",
@@ -34,12 +34,12 @@ Plan: 0 to add, 1 to change, 0 to destroy.
3434
~ crossprovider:index/testRes:TestRes: (update)
3535
[id=newid]
3636
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
37-
~ listAttrs: [
37+
~ props: [
3838
+ [2]: "val3"
3939
]
4040
Resources:
4141
~ 1 to update
4242
1 unchanged
4343
`,
44-
detailedDiff: map[string]interface{}{"listAttrs[2]": map[string]interface{}{}},
44+
detailedDiff: map[string]interface{}{"props[2]": map[string]interface{}{}},
4545
}

0 commit comments

Comments
 (0)