Skip to content

Commit 3c7db4e

Browse files
SDKv2 Diff tests for MaxItemsOne sets (#2839)
This PR adds Diff tests for MaxItemsOne sets for the SDKv2 bridge. fixes #2789
1 parent 9357cbf commit 3c7db4e

File tree

51 files changed

+1442
-1
lines changed

Some content is hidden

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

51 files changed

+1442
-1
lines changed

pkg/tests/diff_test/detailed_diff_set_test.go

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
1010
)
1111

12-
func setScenarios() []diffScenario[[]string] {
12+
func oneElementScenarios() []diffScenario[[]string] {
1313
return []diffScenario[[]string]{
1414
{"unchanged non-empty", &[]string{"value"}, &[]string{"value"}},
1515
{"unchanged empty", &[]string{}, &[]string{}},
@@ -23,7 +23,12 @@ func setScenarios() []diffScenario[[]string] {
2323

2424
{"added", &[]string{}, &[]string{"value"}},
2525
{"removed", &[]string{"value"}, &[]string{}},
26+
}
27+
}
2628

29+
func setScenarios() []diffScenario[[]string] {
30+
scenarios := oneElementScenarios()
31+
multiElementScenarios := []diffScenario[[]string]{
2732
{"removed front", &[]string{"val1", "val2", "val3"}, &[]string{"val2", "val3"}},
2833
{"removed front unordered", &[]string{"val2", "val3", "val1"}, &[]string{"val3", "val1"}},
2934
{"removed middle", &[]string{"val1", "val2", "val3"}, &[]string{"val1", "val3"}},
@@ -61,6 +66,8 @@ func setScenarios() []diffScenario[[]string] {
6166
{"two added and two removed shuffled, no overlaps", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val5", "val6", "val1", "val2"}},
6267
{"two added and two removed shuffled, with duplicates", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val5", "val6", "val2", "val1", "val2"}},
6368
}
69+
70+
return append(scenarios, multiElementScenarios...)
6471
}
6572

6673
func TestSDKv2DetailedDiffSetAttribute(t *testing.T) {
@@ -580,3 +587,96 @@ func TestSDKv2DetailedDiffSetDefault(t *testing.T) {
580587

581588
runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, setScenarios())
582589
}
590+
591+
func TestSDKv2DetailedDiffSetMaxItemsOne(t *testing.T) {
592+
t.Parallel()
593+
594+
maxItemsOneAttrSchema := schema.Resource{
595+
Schema: map[string]*schema.Schema{
596+
"prop": {
597+
Type: schema.TypeSet,
598+
Optional: true,
599+
MaxItems: 1,
600+
Elem: &schema.Schema{Type: schema.TypeString},
601+
},
602+
},
603+
}
604+
605+
maxItemsOneAttrSchemaForceNew := schema.Resource{
606+
Schema: map[string]*schema.Schema{
607+
"prop": {
608+
Type: schema.TypeSet,
609+
Optional: true,
610+
ForceNew: true,
611+
MaxItems: 1,
612+
Elem: &schema.Schema{Type: schema.TypeString},
613+
},
614+
},
615+
}
616+
617+
maxItemsOneBlockSchema := schema.Resource{
618+
Schema: map[string]*schema.Schema{
619+
"prop": {
620+
Type: schema.TypeSet,
621+
Optional: true,
622+
MaxItems: 1,
623+
Elem: &schema.Resource{
624+
Schema: map[string]*schema.Schema{
625+
"nested_prop": {
626+
Type: schema.TypeString,
627+
Optional: true,
628+
},
629+
},
630+
},
631+
},
632+
},
633+
}
634+
635+
maxItemsOneBlockSchemaForceNew := schema.Resource{
636+
Schema: map[string]*schema.Schema{
637+
"prop": {
638+
Type: schema.TypeSet,
639+
Optional: true,
640+
ForceNew: true,
641+
MaxItems: 1,
642+
Elem: &schema.Resource{
643+
Schema: map[string]*schema.Schema{
644+
"nested_prop": {
645+
Type: schema.TypeString,
646+
Optional: true,
647+
},
648+
},
649+
},
650+
},
651+
},
652+
}
653+
654+
maxItemsOneBlockSchemaNestedForceNew := schema.Resource{
655+
Schema: map[string]*schema.Schema{
656+
"prop": {
657+
Type: schema.TypeSet,
658+
Optional: true,
659+
MaxItems: 1,
660+
Elem: &schema.Resource{
661+
Schema: map[string]*schema.Schema{
662+
"nested_prop": {
663+
Type: schema.TypeString,
664+
Optional: true,
665+
ForceNew: true,
666+
},
667+
},
668+
},
669+
},
670+
},
671+
}
672+
673+
diffSchemaValueMakerPairs := []diffSchemaValueMakerPair[[]string]{
674+
{"max items one attribute", maxItemsOneAttrSchema, listValueMaker},
675+
{"max items one attribute force new", maxItemsOneAttrSchemaForceNew, listValueMaker},
676+
{"max items one block", maxItemsOneBlockSchema, nestedListValueMaker},
677+
{"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedListValueMaker},
678+
{"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedListValueMaker},
679+
}
680+
681+
runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, oneElementScenarios())
682+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests.testOutput{
2+
initialValue: &[]string{},
3+
changeValue: &[]string{"value"},
4+
tfOut: `
5+
Terraform used the selected providers to generate the following execution
6+
plan. Resource actions are indicated with the following symbols:
7+
~ update in-place
8+
9+
Terraform will perform the following actions:
10+
11+
# crossprovider_test_res.example will be updated in-place
12+
~ resource "crossprovider_test_res" "example" {
13+
id = "newid"
14+
+ prop = [
15+
+ "value",
16+
]
17+
}
18+
19+
Plan: 0 to add, 1 to change, 0 to destroy.
20+
21+
`,
22+
pulumiOut: `Previewing update (test):
23+
pulumi:pulumi:Stack: (same)
24+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
25+
~ crossprovider:index/testRes:TestRes: (update)
26+
[id=newid]
27+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
28+
+ prop: "value"
29+
Resources:
30+
~ 1 to update
31+
1 unchanged
32+
`,
33+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{}},
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests.testOutput{
2+
initialValue: &[]string{},
3+
changeValue: nil,
4+
tfOut: `
5+
No changes. Your infrastructure matches the configuration.
6+
7+
Terraform has compared your real infrastructure against your configuration
8+
and found no differences, so no changes are needed.
9+
`,
10+
pulumiOut: `Previewing update (test):
11+
pulumi:pulumi:Stack: (same)
12+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
13+
Resources:
14+
2 unchanged
15+
`,
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"value",
4+
},
5+
changeValue: &[]string{"value1"},
6+
tfOut: `
7+
Terraform used the selected providers to generate the following execution
8+
plan. Resource actions are indicated with the following symbols:
9+
~ update in-place
10+
11+
Terraform will perform the following actions:
12+
13+
# crossprovider_test_res.example will be updated in-place
14+
~ resource "crossprovider_test_res" "example" {
15+
id = "newid"
16+
~ prop = [
17+
- "value",
18+
+ "value1",
19+
]
20+
}
21+
22+
Plan: 0 to add, 1 to change, 0 to destroy.
23+
24+
`,
25+
pulumiOut: `Previewing update (test):
26+
pulumi:pulumi:Stack: (same)
27+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
28+
~ crossprovider:index/testRes:TestRes: (update)
29+
[id=newid]
30+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
31+
~ prop: "value" => "value1"
32+
Resources:
33+
~ 1 to update
34+
1 unchanged
35+
`,
36+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"value",
4+
},
5+
changeValue: nil,
6+
tfOut: `
7+
Terraform used the selected providers to generate the following execution
8+
plan. Resource actions are indicated with the following symbols:
9+
~ update in-place
10+
11+
Terraform will perform the following actions:
12+
13+
# crossprovider_test_res.example will be updated in-place
14+
~ resource "crossprovider_test_res" "example" {
15+
id = "newid"
16+
~ prop = [
17+
- "value",
18+
]
19+
}
20+
21+
Plan: 0 to add, 1 to change, 0 to destroy.
22+
23+
`,
24+
pulumiOut: `Previewing update (test):
25+
pulumi:pulumi:Stack: (same)
26+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
27+
~ crossprovider:index/testRes:TestRes: (update)
28+
[id=newid]
29+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
30+
- prop: "value"
31+
Resources:
32+
~ 1 to update
33+
1 unchanged
34+
`,
35+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "DELETE"}},
36+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests.testOutput{
2+
initialValue: nil, changeValue: &[]string{},
3+
tfOut: `
4+
No changes. Your infrastructure matches the configuration.
5+
6+
Terraform has compared your real infrastructure against your configuration
7+
and found no differences, so no changes are needed.
8+
`,
9+
pulumiOut: `Previewing update (test):
10+
pulumi:pulumi:Stack: (same)
11+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
12+
Resources:
13+
2 unchanged
14+
`,
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tests.testOutput{
2+
initialValue: nil, changeValue: &[]string{
3+
"value",
4+
},
5+
tfOut: `
6+
Terraform used the selected providers to generate the following execution
7+
plan. Resource actions are indicated with the following symbols:
8+
~ update in-place
9+
10+
Terraform will perform the following actions:
11+
12+
# crossprovider_test_res.example will be updated in-place
13+
~ resource "crossprovider_test_res" "example" {
14+
id = "newid"
15+
+ prop = [
16+
+ "value",
17+
]
18+
}
19+
20+
Plan: 0 to add, 1 to change, 0 to destroy.
21+
22+
`,
23+
pulumiOut: `Previewing update (test):
24+
pulumi:pulumi:Stack: (same)
25+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
26+
~ crossprovider:index/testRes:TestRes: (update)
27+
[id=newid]
28+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
29+
+ prop: "value"
30+
Resources:
31+
~ 1 to update
32+
1 unchanged
33+
`,
34+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{}},
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"value",
4+
},
5+
changeValue: &[]string{},
6+
tfOut: `
7+
Terraform used the selected providers to generate the following execution
8+
plan. Resource actions are indicated with the following symbols:
9+
~ update in-place
10+
11+
Terraform will perform the following actions:
12+
13+
# crossprovider_test_res.example will be updated in-place
14+
~ resource "crossprovider_test_res" "example" {
15+
id = "newid"
16+
~ prop = [
17+
- "value",
18+
]
19+
}
20+
21+
Plan: 0 to add, 1 to change, 0 to destroy.
22+
23+
`,
24+
pulumiOut: `Previewing update (test):
25+
pulumi:pulumi:Stack: (same)
26+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
27+
~ crossprovider:index/testRes:TestRes: (update)
28+
[id=newid]
29+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
30+
- prop: "value"
31+
Resources:
32+
~ 1 to update
33+
1 unchanged
34+
`,
35+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "DELETE"}},
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests.testOutput{
2+
initialValue: &[]string{},
3+
changeValue: &[]string{},
4+
tfOut: `
5+
No changes. Your infrastructure matches the configuration.
6+
7+
Terraform has compared your real infrastructure against your configuration
8+
and found no differences, so no changes are needed.
9+
`,
10+
pulumiOut: `Previewing update (test):
11+
pulumi:pulumi:Stack: (same)
12+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
13+
Resources:
14+
2 unchanged
15+
`,
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"value",
4+
},
5+
changeValue: &[]string{"value"},
6+
tfOut: `
7+
No changes. Your infrastructure matches the configuration.
8+
9+
Terraform has compared your real infrastructure against your configuration
10+
and found no differences, so no changes are needed.
11+
`,
12+
pulumiOut: `Previewing update (test):
13+
pulumi:pulumi:Stack: (same)
14+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
15+
Resources:
16+
2 unchanged
17+
`,
18+
}

0 commit comments

Comments
 (0)