Skip to content

Commit

Permalink
Add SDKv2 Detailed Diff tests for lists with many elements
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 13, 2024
1 parent 5d5e3d0 commit d7e5748
Show file tree
Hide file tree
Showing 21 changed files with 2,293 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/tests/detailed_diff_list_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -269,6 +270,14 @@ func TestDetailedDiffList(t *testing.T) {
{"changed", ref([]string{"val1"}), ref([]string{"val2"})},
}

longList := &[]string{}
for i := 0; i < 20; i++ {
*longList = append(*longList, fmt.Sprintf("value%d", i))
}
longListAddedBack := append([]string{}, *longList...)
longListAddedBack = append(longListAddedBack, "value20")
longListAddedFront := append([]string{"value20"}, *longList...)

multiElementScenarios := []struct {
name string
initialValue *[]string
Expand All @@ -280,6 +289,12 @@ func TestDetailedDiffList(t *testing.T) {
{"list element removed front", ref([]string{"val1", "val2", "val3"}), ref([]string{"val3", "val2"})},
{"list element removed middle", ref([]string{"val1", "val2", "val3"}), ref([]string{"val3", "val1"})},
{"list element removed end", ref([]string{"val1", "val2", "val3"}), ref([]string{"val2", "val1"})},
{"one added, one removed", ref([]string{"val1", "val2", "val3"}), ref([]string{"val2", "val3", "val4"})},
{"long list added back", longList, &longListAddedBack},
// TODO[pulumi/pulumi-terraform-bridge#2239]: These cases present as multiple changes instead of just one
{"long list added front", longList, &longListAddedFront},
{"long list removed front", &longListAddedFront, longList},
{"long list removed back", &longListAddedBack, longList},
}

scenarios := append(oneElementScenarios, multiElementScenarios...)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
tests.testOutput{
initialValue: &[]string{
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
},
changeValue: &[]string{
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
"value20",
},
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_attr = [
# (19 unchanged elements hidden)
"value19",
+ "value20",
]
}

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]
~ listAttrs: [
+ [20]: "value20"
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listAttrs[20]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
tests.testOutput{
initialValue: &[]string{
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
},
changeValue: &[]string{
"value20",
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
},
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_attr = [
+ "value20",
"value0",
# (19 unchanged elements 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]
~ listAttrs: [
~ [0]: "value0" => "value20"
~ [1]: "value1" => "value0"
~ [2]: "value2" => "value1"
~ [3]: "value3" => "value2"
~ [4]: "value4" => "value3"
~ [5]: "value5" => "value4"
~ [6]: "value6" => "value5"
~ [7]: "value7" => "value6"
~ [8]: "value8" => "value7"
~ [9]: "value9" => "value8"
~ [10]: "value10" => "value9"
~ [11]: "value11" => "value10"
~ [12]: "value12" => "value11"
~ [13]: "value13" => "value12"
~ [14]: "value14" => "value13"
~ [15]: "value15" => "value14"
~ [16]: "value16" => "value15"
~ [17]: "value17" => "value16"
~ [18]: "value18" => "value17"
~ [19]: "value19" => "value18"
+ [20]: "value19"
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"listAttrs[0]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[10]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[11]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[12]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[13]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[14]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[15]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[16]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[17]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[18]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[19]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[1]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[20]": map[string]interface{}{},
"listAttrs[2]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[3]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[4]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[5]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[6]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[7]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[8]": map[string]interface{}{"kind": "UPDATE"},
"listAttrs[9]": map[string]interface{}{"kind": "UPDATE"},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
tests.testOutput{
initialValue: &[]string{
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
"value20",
},
changeValue: &[]string{
"value0",
"value1",
"value2",
"value3",
"value4",
"value5",
"value6",
"value7",
"value8",
"value9",
"value10",
"value11",
"value12",
"value13",
"value14",
"value15",
"value16",
"value17",
"value18",
"value19",
},
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_attr = [
# (19 unchanged elements hidden)
"value19",
- "value20",
]
}

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]
~ listAttrs: [
- [20]: "value20"
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listAttrs[20]": map[string]interface{}{"kind": "DELETE"}},
}
Loading

0 comments on commit d7e5748

Please sign in to comment.