Skip to content

Commit 9660285

Browse files
SDKv2 Diff tests for primitive types (#2829)
This PR finishes the test coverage for primitive types (string, bool, int and float) for the SDKv2 bridge for Diff. [14807c6](14807c6) and [8552a4a](8552a4a) contain the test recordings. fixes #2786
1 parent cb11d40 commit 9660285

File tree

163 files changed

+4175
-68
lines changed

Some content is hidden

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

163 files changed

+4175
-68
lines changed

pkg/tests/diff_test/detailed_diff_test.go renamed to pkg/tests/diff_test/detailed_diff_map_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,6 @@ import (
1010
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests"
1111
)
1212

13-
func TestSDKv2DetailedDiffString(t *testing.T) {
14-
t.Parallel()
15-
16-
res := schema.Resource{
17-
Schema: map[string]*schema.Schema{
18-
"string_prop": {
19-
Type: schema.TypeString,
20-
Optional: true,
21-
},
22-
},
23-
}
24-
25-
valueOne := ref("val1")
26-
valueTwo := ref("val2")
27-
var noValue *string
28-
29-
ctyVal := func(v *string) map[string]cty.Value {
30-
if v == nil {
31-
return map[string]cty.Value{}
32-
}
33-
return map[string]cty.Value{
34-
"string_prop": cty.StringVal(*v),
35-
}
36-
}
37-
38-
scenarios := []struct {
39-
name string
40-
initialValue *string
41-
changeValue *string
42-
}{
43-
{"unchanged empty", noValue, noValue},
44-
{"unchanged non-empty", valueOne, valueOne},
45-
{"added", noValue, valueOne},
46-
{"removed", valueOne, noValue},
47-
{"changed", valueOne, valueTwo},
48-
}
49-
50-
for _, scenario := range scenarios {
51-
t.Run(scenario.name, func(t *testing.T) {
52-
t.Parallel()
53-
diff := crosstests.Diff(t, &res, ctyVal(scenario.initialValue), ctyVal(scenario.changeValue))
54-
autogold.ExpectFile(t, testOutput{
55-
initialValue: scenario.initialValue,
56-
changeValue: scenario.changeValue,
57-
tfOut: diff.TFOut,
58-
pulumiOut: diff.PulumiOut,
59-
detailedDiff: diff.PulumiDiff.DetailedDiff,
60-
})
61-
})
62-
}
63-
}
64-
6513
func TestSDKv2DetailedDiffMap(t *testing.T) {
6614
t.Parallel()
6715

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
"github.com/zclconf/go-cty/cty"
8+
)
9+
10+
func TestSDKv2DetailedDiffString(t *testing.T) {
11+
t.Parallel()
12+
13+
var nilVal string
14+
schemaValueMakerPairs, scenarios := generateBaseTests(
15+
schema.TypeString, cty.StringVal, "val1", "val2", "computed", "default", nilVal)
16+
17+
runSDKv2TestMatrix(t, schemaValueMakerPairs, scenarios)
18+
}
19+
20+
func TestSDKv2DetailedDiffBool(t *testing.T) {
21+
t.Parallel()
22+
23+
var nilVal bool
24+
schemaValueMakerPairs, scenarios := generateBaseTests(
25+
schema.TypeBool, cty.BoolVal, true, false, true, false, nilVal)
26+
27+
runSDKv2TestMatrix(t, schemaValueMakerPairs, scenarios)
28+
}
29+
30+
func TestSDKv2DetailedDiffInt(t *testing.T) {
31+
t.Parallel()
32+
33+
var nilVal int64
34+
schemaValueMakerPairs, scenarios := generateBaseTests(
35+
schema.TypeInt, cty.NumberIntVal, 1, 2, 3, 4, nilVal)
36+
37+
runSDKv2TestMatrix(t, schemaValueMakerPairs, scenarios)
38+
}
39+
40+
func TestSDKv2DetailedDiffFloat(t *testing.T) {
41+
t.Parallel()
42+
43+
var nilVal float64
44+
schemaValueMakerPairs, scenarios := generateBaseTests(
45+
schema.TypeFloat, cty.NumberFloatVal, 1.0, 2.0, 3.0, 4.0, nilVal)
46+
47+
runSDKv2TestMatrix(t, schemaValueMakerPairs, scenarios)
48+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(false), changeValue: valast.Ptr(true),
3+
tfOut: `
4+
Terraform used the selected providers to generate the following execution
5+
plan. Resource actions are indicated with the following symbols:
6+
~ update in-place
7+
8+
Terraform will perform the following actions:
9+
10+
# crossprovider_test_res.example will be updated in-place
11+
~ resource "crossprovider_test_res" "example" {
12+
id = "newid"
13+
~ prop = false -> true
14+
}
15+
16+
Plan: 0 to add, 1 to change, 0 to destroy.
17+
18+
`,
19+
pulumiOut: `Previewing update (test):
20+
pulumi:pulumi:Stack: (same)
21+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
22+
~ crossprovider:index/testRes:TestRes: (update)
23+
[id=newid]
24+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
25+
~ prop: false => true
26+
Resources:
27+
~ 1 to update
28+
1 unchanged
29+
`,
30+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(true), changeValue: valast.Ptr(false),
3+
tfOut: `
4+
Terraform used the selected providers to generate the following execution
5+
plan. Resource actions are indicated with the following symbols:
6+
~ update in-place
7+
8+
Terraform will perform the following actions:
9+
10+
# crossprovider_test_res.example will be updated in-place
11+
~ resource "crossprovider_test_res" "example" {
12+
id = "newid"
13+
~ prop = true -> false
14+
}
15+
16+
Plan: 0 to add, 1 to change, 0 to destroy.
17+
18+
`,
19+
pulumiOut: `Previewing update (test):
20+
pulumi:pulumi:Stack: (same)
21+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
22+
~ crossprovider:index/testRes:TestRes: (update)
23+
[id=newid]
24+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
25+
~ prop: true => false
26+
Resources:
27+
~ 1 to update
28+
1 unchanged
29+
`,
30+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
31+
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffString/removed.golden renamed to pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffBool/optional/removed.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests.testOutput{
2-
initialValue: valast.Ptr("val1"), changeValue: nil,
2+
initialValue: valast.Ptr(true), changeValue: valast.Ptr(false),
33
tfOut: `
44
Terraform used the selected providers to generate the following execution
55
plan. Resource actions are indicated with the following symbols:
@@ -9,8 +9,8 @@ Terraform will perform the following actions:
99

1010
# crossprovider_test_res.example will be updated in-place
1111
~ resource "crossprovider_test_res" "example" {
12-
id = "newid"
13-
- string_prop = "val1" -> null
12+
id = "newid"
13+
~ prop = true -> false
1414
}
1515

1616
Plan: 0 to add, 1 to change, 0 to destroy.
@@ -22,10 +22,10 @@ Plan: 0 to add, 1 to change, 0 to destroy.
2222
~ crossprovider:index/testRes:TestRes: (update)
2323
[id=newid]
2424
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
25-
- stringProp: "val1"
25+
~ prop: true => false
2626
Resources:
2727
~ 1 to update
2828
1 unchanged
2929
`,
30-
detailedDiff: map[string]interface{}{"stringProp": map[string]interface{}{"kind": "DELETE"}},
30+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
3131
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(false), changeValue: valast.Ptr(false),
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(true), changeValue: valast.Ptr(true),
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(false), changeValue: valast.Ptr(true),
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(true), changeValue: valast.Ptr(false),
3+
tfOut: `
4+
Terraform used the selected providers to generate the following execution
5+
plan. Resource actions are indicated with the following symbols:
6+
~ update in-place
7+
8+
Terraform will perform the following actions:
9+
10+
# crossprovider_test_res.example will be updated in-place
11+
~ resource "crossprovider_test_res" "example" {
12+
id = "id"
13+
~ prop = true -> false
14+
}
15+
16+
Plan: 0 to add, 1 to change, 0 to destroy.
17+
18+
`,
19+
pulumiOut: `Previewing update (test):
20+
pulumi:pulumi:Stack: (same)
21+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
22+
~ crossprovider:index/testRes:TestRes: (update)
23+
[id=id]
24+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
25+
~ prop: true => false
26+
Resources:
27+
~ 1 to update
28+
1 unchanged
29+
`,
30+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests.testOutput{
2+
initialValue: valast.Ptr(true), changeValue: valast.Ptr(false),
3+
tfOut: `
4+
Terraform used the selected providers to generate the following execution
5+
plan. Resource actions are indicated with the following symbols:
6+
~ update in-place
7+
8+
Terraform will perform the following actions:
9+
10+
# crossprovider_test_res.example will be updated in-place
11+
~ resource "crossprovider_test_res" "example" {
12+
id = "id"
13+
~ prop = true -> false
14+
}
15+
16+
Plan: 0 to add, 1 to change, 0 to destroy.
17+
18+
`,
19+
pulumiOut: `Previewing update (test):
20+
pulumi:pulumi:Stack: (same)
21+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
22+
~ crossprovider:index/testRes:TestRes: (update)
23+
[id=id]
24+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
25+
~ prop: true => false
26+
Resources:
27+
~ 1 to update
28+
1 unchanged
29+
`,
30+
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
31+
}

0 commit comments

Comments
 (0)