Skip to content

Commit

Permalink
Re-enable detailed diff replace tests for SDKv2 lists and sets (#2751)
Browse files Browse the repository at this point in the history
This re-enables the detailed diff replace tests for the SDKv2 bridge for
lists and sets. These were previously skipped because of
#2726 which is
fixed in #2747
  • Loading branch information
VenelinMartinov authored Dec 17, 2024
1 parent 6f2c424 commit 44613e8
Show file tree
Hide file tree
Showing 74 changed files with 2,879 additions and 39 deletions.
8 changes: 3 additions & 5 deletions pkg/tests/detailed_diff_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ func TestDetailedDiffList(t *testing.T) {
{"list attribute force new", listAttrSchemaForceNew, attrList},
{"list block", listBlockSchema, blockList},
{"list block force new", listBlockSchemaForceNew, blockList},
// TODO[pulumi/pulumi-terraform-bridge#2726]: These tests fail to produce the correct replacement plan
// {"list block nested force new", listBlockSchemaNestedForceNew, blockList},
{"list block nested force new", listBlockSchemaNestedForceNew, blockList},
}

maxItemsOnePairs := []struct {
Expand All @@ -251,9 +250,8 @@ func TestDetailedDiffList(t *testing.T) {
{"max items one attribute", maxItemsOneAttrSchema, attrList},
{"max items one attribute force new", maxItemsOneAttrSchemaForceNew, attrList},
{"max items one block", maxItemsOneBlockSchema, nestedBlockList},
// TODO[pulumi/pulumi-terraform-bridge#2726]: These tests fail to produce the correct replacement plan
// {"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedBlockList},
// {"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedBlockList},
{"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedBlockList},
{"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedBlockList},
}

oneElementScenarios := []struct {
Expand Down
38 changes: 4 additions & 34 deletions pkg/tests/detailed_diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,22 +890,15 @@ func TestDetailedDiffSet(t *testing.T) {
return cty.ListVal(slice)
}

noForceNewSchemaValueMakerPairs := []struct {
schemaValueMakerPairs := []struct {
name string
res schema.Resource
valueMaker func(*[]string) cty.Value
}{
{"attribute no force new", attributeSchema, attrList},
{"block no force new", blockSchema, nestedAttrList},
}

forceNewSchemaValueMakerPairs := []struct {
name string
res schema.Resource
valueMaker func(*[]string) cty.Value
}{
{"attribute force new", attributeSchemaForceNew, attrList},
{"block top level force new", blockSchemaForceNew, nestedAttrList},
{"block force new", blockSchemaForceNew, nestedAttrList},
{"block nested force new", blockSchemaNestedForceNew, nestedAttrList},
}

Expand Down Expand Up @@ -942,6 +935,7 @@ func TestDetailedDiffSet(t *testing.T) {
{"added end unordered", &[]string{"val2", "val3"}, &[]string{"val2", "val3", "val1"}},

{"same element updated", &[]string{"val1", "val2", "val3"}, &[]string{"val1", "val4", "val3"}},
{"same element updated unordered", &[]string{"val2", "val3", "val1"}, &[]string{"val2", "val4", "val1"}},

{"shuffled", &[]string{"val1", "val2", "val3"}, &[]string{"val3", "val1", "val2"}},
{"shuffled unordered", &[]string{"val2", "val3", "val1"}, &[]string{"val3", "val1", "val2"}},
Expand All @@ -958,24 +952,12 @@ func TestDetailedDiffSet(t *testing.T) {

{"two added", &[]string{"val1", "val2"}, &[]string{"val1", "val2", "val3", "val4"}},
{"two removed", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val2"}},
}

// TODO[pulumi/pulumi-terraform-bridge#2726]: These tests fail to produce the correct replacement plan
// for the force new shcemas
extraScenarios := []struct {
name string
initialValue *[]string
changeValue *[]string
}{
{"same element updated unordered", &[]string{"val2", "val3", "val1"}, &[]string{"val2", "val4", "val1"}},
{"two added and two removed", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val2", "val5", "val6"}},
{"two added and two removed shuffled, one overlaps", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val5", "val6", "val2"}},
{"two added and two removed shuffled, no overlaps", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val5", "val6", "val1", "val2"}},
{"two added and two removed shuffled, with duplicates", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val5", "val6", "val2", "val1", "val2"}},
}

allScenarios := append(scenarios, extraScenarios...)

type testOutput struct {
initialValue *[]string
changeValue *[]string
Expand All @@ -999,7 +981,7 @@ func TestDetailedDiffSet(t *testing.T) {
})
}

for _, schemaValueMakerPair := range forceNewSchemaValueMakerPairs {
for _, schemaValueMakerPair := range schemaValueMakerPairs {
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
t.Parallel()
for _, scenario := range scenarios {
Expand All @@ -1010,16 +992,4 @@ func TestDetailedDiffSet(t *testing.T) {
}
})
}

for _, schemaValueMakerPair := range noForceNewSchemaValueMakerPairs {
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
t.Parallel()
for _, scenario := range allScenarios {
t.Run(scenario.name, func(t *testing.T) {
t.Parallel()
runTest(t, schemaValueMakerPair.res, schemaValueMakerPair.valueMaker, scenario.initialValue, scenario.changeValue)
})
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests.testOutput{
changeValue: &[]string{},
tfOut: `
No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
Resources:
2 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
tests.testOutput{
changeValue: &[]string{
"val1",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {}
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
+ listBlocks: [
+ [0]: {
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests.testOutput{
initialValue: &[]string{
"val1",
},
changeValue: &[]string{"val2"},
tfOut: `
No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
Resources:
2 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val2",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {}

# (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
+ [2]: {
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
tests.testOutput{
initialValue: &[]string{
"val2",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {}

# (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
+ [2]: {
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {}

# (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
+ [2]: {
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val2",
"val3",
},
changeValue: &[]string{
"val2",
"val1",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

- list_block {}

# (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
- [2]: {
- nestedProp: <null>
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{"kind": "DELETE"}},
}
Loading

0 comments on commit 44613e8

Please sign in to comment.