Skip to content

Commit 6fa352c

Browse files
Detailed diff tests for properties with dot in the name
1 parent 1aa2e64 commit 6fa352c

File tree

9 files changed

+415
-13
lines changed

9 files changed

+415
-13
lines changed

pkg/internal/tests/cross-tests/diff_check.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ func runDiffCheck(t T, tc diffTestCase) crosstestsimpl.DiffResult {
5959

6060
resMap := map[string]*schema.Resource{defRtype: tc.Resource}
6161
tfp := &schema.Provider{ResourcesMap: resMap}
62-
bridgedProvider := pulcheck.BridgedProvider(t, defProviderShortName, tfp, pulcheck.EnableAccurateBridgePreviews())
62+
opts := []pulcheck.BridgedProviderOpt{}
63+
if os.Getenv("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW") != "false" {
64+
opts = append(opts, pulcheck.EnableAccurateBridgePreviews())
65+
}
66+
bridgedProvider := pulcheck.BridgedProvider(t, defProviderShortName, tfp, opts...)
6367
if tc.DeleteBeforeReplace {
6468
bridgedProvider.Resources[defRtype].DeleteBeforeReplace = true
6569
}

pkg/internal/tests/cross-tests/diff_cross_test.go

+122-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"hash/crc32"
2222
"slices"
23+
"strconv"
2324
"strings"
2425
"testing"
2526

@@ -1625,6 +1626,14 @@ func TestBlockCollectionElementForceNew(t *testing.T) {
16251626
})
16261627
}
16271628

1629+
type diffTestOutput struct {
1630+
initialValue cty.Value
1631+
changeValue cty.Value
1632+
tfOut string
1633+
pulumiOut string
1634+
detailedDiff map[string]any
1635+
}
1636+
16281637
func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
16291638
t.Parallel()
16301639
// TODO[pulumi/pulumi-terraform-bridge#2660]
@@ -1650,14 +1659,6 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
16501659
},
16511660
}
16521661

1653-
type testOutput struct {
1654-
initialValue cty.Value
1655-
changeValue cty.Value
1656-
tfOut string
1657-
pulumiOut string
1658-
detailedDiff map[string]any
1659-
}
1660-
16611662
t.Run("no change", func(t *testing.T) {
16621663
t.Parallel()
16631664
initialValue := cty.ObjectVal(map[string]cty.Value{})
@@ -1668,7 +1669,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
16681669
Config2: changeValue,
16691670
})
16701671

1671-
autogold.ExpectFile(t, testOutput{
1672+
autogold.ExpectFile(t, diffTestOutput{
16721673
initialValue: initialValue,
16731674
changeValue: changeValue,
16741675
tfOut: diff.TFOut,
@@ -1687,7 +1688,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
16871688
Config2: changeValue,
16881689
})
16891690

1690-
autogold.ExpectFile(t, testOutput{
1691+
autogold.ExpectFile(t, diffTestOutput{
16911692
initialValue: initialValue,
16921693
changeValue: changeValue,
16931694
tfOut: diff.TFOut,
@@ -1706,7 +1707,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
17061707
Config2: changeValue,
17071708
})
17081709

1709-
autogold.ExpectFile(t, testOutput{
1710+
autogold.ExpectFile(t, diffTestOutput{
17101711
initialValue: initialValue,
17111712
changeValue: changeValue,
17121713
tfOut: diff.TFOut,
@@ -1725,7 +1726,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
17251726
Config2: changeValue,
17261727
})
17271728

1728-
autogold.ExpectFile(t, testOutput{
1729+
autogold.ExpectFile(t, diffTestOutput{
17291730
initialValue: initialValue,
17301731
changeValue: changeValue,
17311732
tfOut: diff.TFOut,
@@ -1734,3 +1735,112 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
17341735
})
17351736
})
17361737
}
1738+
1739+
func TestPropertyWithDot(t *testing.T) {
1740+
res := &schema.Resource{
1741+
Schema: map[string]*schema.Schema{
1742+
"prop": {
1743+
Type: schema.TypeList,
1744+
Optional: true,
1745+
MaxItems: 1,
1746+
Elem: &schema.Resource{
1747+
Schema: map[string]*schema.Schema{
1748+
"foo": {
1749+
Type: schema.TypeString,
1750+
Optional: true,
1751+
},
1752+
},
1753+
},
1754+
},
1755+
},
1756+
}
1757+
1758+
for _, accuratePreivewsEnabled := range []bool{true, false} {
1759+
t.Run(fmt.Sprintf("accuratePreivewsEnabled=%v", accuratePreivewsEnabled), func(t *testing.T) {
1760+
t.Setenv("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW", strconv.FormatBool(accuratePreivewsEnabled))
1761+
t.Run("unchanged", func(t *testing.T) {
1762+
initialValue := cty.ObjectVal(map[string]cty.Value{
1763+
"prop": cty.ListVal([]cty.Value{
1764+
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
1765+
}),
1766+
})
1767+
changeValue := cty.ObjectVal(map[string]cty.Value{
1768+
"prop": cty.ListVal([]cty.Value{
1769+
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
1770+
}),
1771+
})
1772+
diff := runDiffCheck(t, diffTestCase{
1773+
Resource: res,
1774+
Config1: initialValue,
1775+
Config2: changeValue,
1776+
})
1777+
1778+
autogold.ExpectFile(t, diffTestOutput{
1779+
initialValue: initialValue,
1780+
changeValue: changeValue,
1781+
tfOut: diff.TFOut,
1782+
pulumiOut: diff.PulumiOut,
1783+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1784+
})
1785+
})
1786+
1787+
t.Run("added", func(t *testing.T) {
1788+
initialValue := cty.ObjectVal(map[string]cty.Value{
1789+
"prop": cty.ListVal([]cty.Value{
1790+
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
1791+
}),
1792+
})
1793+
changeValue := cty.ObjectVal(map[string]cty.Value{
1794+
"prop": cty.ListVal([]cty.Value{
1795+
cty.ObjectVal(map[string]cty.Value{
1796+
"foo": cty.StringVal("bar"),
1797+
"foo.bar": cty.StringVal("baz"),
1798+
}),
1799+
}),
1800+
})
1801+
diff := runDiffCheck(t, diffTestCase{
1802+
Resource: res,
1803+
Config1: initialValue,
1804+
Config2: changeValue,
1805+
})
1806+
1807+
autogold.ExpectFile(t, diffTestOutput{
1808+
initialValue: initialValue,
1809+
changeValue: changeValue,
1810+
tfOut: diff.TFOut,
1811+
pulumiOut: diff.PulumiOut,
1812+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1813+
})
1814+
})
1815+
1816+
t.Run("deleted", func(t *testing.T) {
1817+
initialValue := cty.ObjectVal(map[string]cty.Value{
1818+
"prop": cty.ListVal([]cty.Value{
1819+
cty.ObjectVal(map[string]cty.Value{
1820+
"foo": cty.StringVal("bar"),
1821+
"foo.bar": cty.StringVal("baz"),
1822+
}),
1823+
}),
1824+
})
1825+
changeValue := cty.ObjectVal(map[string]cty.Value{
1826+
"prop": cty.ListVal([]cty.Value{
1827+
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
1828+
}),
1829+
})
1830+
diff := runDiffCheck(t, diffTestCase{
1831+
Resource: res,
1832+
Config1: initialValue,
1833+
Config2: changeValue,
1834+
})
1835+
1836+
autogold.ExpectFile(t, diffTestOutput{
1837+
initialValue: initialValue,
1838+
changeValue: changeValue,
1839+
tfOut: diff.TFOut,
1840+
pulumiOut: diff.PulumiOut,
1841+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1842+
})
1843+
})
1844+
})
1845+
}
1846+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
crosstests.diffTestOutput{
2+
initialValue: cty.Value{
3+
ty: cty.Type{typeImpl: cty.typeObject{
4+
AttrTypes: map[string]cty.Type{"prop": {
5+
typeImpl: cty.typeList{ElementTypeT: cty.Type{
6+
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
7+
"foo": {typeImpl: cty.primitiveType{
8+
Kind: cty.primitiveTypeKind(83),
9+
}},
10+
}},
11+
}},
12+
}},
13+
}},
14+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
15+
},
16+
changeValue: cty.Value{
17+
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
18+
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
19+
AttrTypes: map[string]cty.Type{
20+
"foo": {
21+
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
22+
},
23+
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
24+
},
25+
}},
26+
}}}}},
27+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
28+
"foo": "bar",
29+
"foo.bar": "baz",
30+
}}},
31+
},
32+
tfOut: `
33+
No changes. Your infrastructure matches the configuration.
34+
35+
Terraform has compared your real infrastructure against your configuration
36+
and found no differences, so no changes are needed.
37+
`,
38+
pulumiOut: `Previewing update (test):
39+
pulumi:pulumi:Stack: (same)
40+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
41+
Resources:
42+
2 unchanged
43+
`,
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
crosstests.diffTestOutput{
2+
initialValue: cty.Value{
3+
ty: cty.Type{typeImpl: cty.typeObject{
4+
AttrTypes: map[string]cty.Type{"prop": {
5+
typeImpl: cty.typeList{ElementTypeT: cty.Type{
6+
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
7+
"foo": {typeImpl: cty.primitiveType{
8+
Kind: cty.primitiveTypeKind(83),
9+
}},
10+
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
11+
}},
12+
}},
13+
}},
14+
}},
15+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
16+
"foo": "bar",
17+
"foo.bar": "baz",
18+
}}},
19+
},
20+
changeValue: cty.Value{
21+
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
22+
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
23+
AttrTypes: map[string]cty.Type{"foo": {
24+
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
25+
}},
26+
}},
27+
}}}}},
28+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
29+
},
30+
tfOut: `
31+
No changes. Your infrastructure matches the configuration.
32+
33+
Terraform has compared your real infrastructure against your configuration
34+
and found no differences, so no changes are needed.
35+
`,
36+
pulumiOut: `Previewing update (test):
37+
pulumi:pulumi:Stack: (same)
38+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
39+
Resources:
40+
2 unchanged
41+
`,
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
crosstests.diffTestOutput{
2+
initialValue: cty.Value{
3+
ty: cty.Type{typeImpl: cty.typeObject{
4+
AttrTypes: map[string]cty.Type{"prop": {
5+
typeImpl: cty.typeList{ElementTypeT: cty.Type{
6+
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
7+
"foo.bar": {typeImpl: cty.primitiveType{
8+
Kind: cty.primitiveTypeKind(83),
9+
}},
10+
}},
11+
}},
12+
}},
13+
}},
14+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo.bar": "baz"}}},
15+
},
16+
changeValue: cty.Value{
17+
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
18+
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
19+
AttrTypes: map[string]cty.Type{"foo.bar": {
20+
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
21+
}},
22+
}},
23+
}}}}},
24+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo.bar": "baz"}}},
25+
},
26+
tfOut: `
27+
No changes. Your infrastructure matches the configuration.
28+
29+
Terraform has compared your real infrastructure against your configuration
30+
and found no differences, so no changes are needed.
31+
`,
32+
pulumiOut: `Previewing update (test):
33+
pulumi:pulumi:Stack: (same)
34+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
35+
Resources:
36+
2 unchanged
37+
`,
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
crosstests.diffTestOutput{
2+
initialValue: cty.Value{
3+
ty: cty.Type{typeImpl: cty.typeObject{
4+
AttrTypes: map[string]cty.Type{"prop": {
5+
typeImpl: cty.typeList{ElementTypeT: cty.Type{
6+
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
7+
"foo": {typeImpl: cty.primitiveType{
8+
Kind: cty.primitiveTypeKind(83),
9+
}},
10+
}},
11+
}},
12+
}},
13+
}},
14+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
15+
},
16+
changeValue: cty.Value{
17+
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
18+
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
19+
AttrTypes: map[string]cty.Type{
20+
"foo": {
21+
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
22+
},
23+
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
24+
},
25+
}},
26+
}}}}},
27+
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
28+
"foo": "bar",
29+
"foo.bar": "baz",
30+
}}},
31+
},
32+
tfOut: `
33+
No changes. Your infrastructure matches the configuration.
34+
35+
Terraform has compared your real infrastructure against your configuration
36+
and found no differences, so no changes are needed.
37+
`,
38+
pulumiOut: `Previewing update (test):
39+
pulumi:pulumi:Stack: (same)
40+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
41+
Resources:
42+
2 unchanged
43+
`,
44+
}

0 commit comments

Comments
 (0)