Skip to content

Commit

Permalink
SDKv2 Diff tests for secret set type (#2836)
Browse files Browse the repository at this point in the history
This adds Diff tests for the SDKv2 bridge for secrets in set types.

Fixes #2791
  • Loading branch information
VenelinMartinov authored Jan 17, 2025
1 parent 278674c commit ec61116
Show file tree
Hide file tree
Showing 81 changed files with 3,452 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/tests/diff_test/detailed_diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,57 @@ func TestSDKv2DetailedDiffSetNestedComputedBlock(t *testing.T) {
})
}
}

func TestSDKv2DetailedDiffSetBlockSensitive(t *testing.T) {
t.Parallel()

blockSchemaSensitive := schema.Resource{
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeSet,
Optional: true,
Sensitive: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}

blockSchemaNestedSensitive := schema.Resource{
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
},
},
},
},
}

setSchemaValueMakerPairs := []setSchemaValueMakerPair{
{"block sensitive", blockSchemaSensitive, nestedListValueMaker},
{"block nested sensitive", blockSchemaNestedSensitive, nestedListValueMaker},
}

for _, schemaValueMakerPair := range setSchemaValueMakerPairs {
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
t.Parallel()
for _, scenario := range setScenarios() {
t.Run(scenario.name, runSetTest(schemaValueMakerPair.res, schemaValueMakerPair.valueMaker, scenario.initialValue, scenario.changeValue, false))
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tests.testOutput{
initialValue: &[]string{},
changeValue: &[]string{"value"},
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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}
}

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]
+ tests: [secret]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tests.testOutput{
initialValue: &[]string{
"val2",
"val3",
},
changeValue: &[]string{
"val2",
"val3",
"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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [0]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[0]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tests.testOutput{
initialValue: &[]string{
"val3",
"val1",
},
changeValue: &[]string{
"val2",
"val3",
"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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [0]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[0]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [1]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[1]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tests.testOutput{
initialValue: &[]string{
"val2",
"val1",
},
changeValue: &[]string{
"val2",
"val3",
"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"

+ test {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
}

# (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]
~ tests: [
+ [1]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[1]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests.testOutput{
initialValue: &[]string{},
changeValue: nil,
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
`,
}
Loading

0 comments on commit ec61116

Please sign in to comment.