Skip to content

Commit 28c249d

Browse files
Detailed diff tests for properties with dot in the name
1 parent bc07e11 commit 28c249d

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

@@ -1649,14 +1658,6 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
16491658
},
16501659
}
16511660

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

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

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

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

1727-
autogold.ExpectFile(t, testOutput{
1728+
autogold.ExpectFile(t, diffTestOutput{
17281729
initialValue: initialValue,
17291730
changeValue: changeValue,
17301731
tfOut: diff.TFOut,
@@ -1733,3 +1734,112 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
17331734
})
17341735
})
17351736
}
1737+
1738+
func TestPropertyWithDot(t *testing.T) {
1739+
res := &schema.Resource{
1740+
Schema: map[string]*schema.Schema{
1741+
"prop": {
1742+
Type: schema.TypeList,
1743+
Optional: true,
1744+
MaxItems: 1,
1745+
Elem: &schema.Resource{
1746+
Schema: map[string]*schema.Schema{
1747+
"foo": {
1748+
Type: schema.TypeString,
1749+
Optional: true,
1750+
},
1751+
},
1752+
},
1753+
},
1754+
},
1755+
}
1756+
1757+
for _, accuratePreivewsEnabled := range []bool{true, false} {
1758+
t.Run(fmt.Sprintf("accuratePreivewsEnabled=%v", accuratePreivewsEnabled), func(t *testing.T) {
1759+
t.Setenv("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW", strconv.FormatBool(accuratePreivewsEnabled))
1760+
t.Run("unchanged", func(t *testing.T) {
1761+
initialValue := cty.ObjectVal(map[string]cty.Value{
1762+
"prop": cty.ListVal([]cty.Value{
1763+
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
1764+
}),
1765+
})
1766+
changeValue := cty.ObjectVal(map[string]cty.Value{
1767+
"prop": cty.ListVal([]cty.Value{
1768+
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
1769+
}),
1770+
})
1771+
diff := runDiffCheck(t, diffTestCase{
1772+
Resource: res,
1773+
Config1: initialValue,
1774+
Config2: changeValue,
1775+
})
1776+
1777+
autogold.ExpectFile(t, diffTestOutput{
1778+
initialValue: initialValue,
1779+
changeValue: changeValue,
1780+
tfOut: diff.TFOut,
1781+
pulumiOut: diff.PulumiOut,
1782+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1783+
})
1784+
})
1785+
1786+
t.Run("added", func(t *testing.T) {
1787+
initialValue := cty.ObjectVal(map[string]cty.Value{
1788+
"prop": cty.ListVal([]cty.Value{
1789+
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
1790+
}),
1791+
})
1792+
changeValue := cty.ObjectVal(map[string]cty.Value{
1793+
"prop": cty.ListVal([]cty.Value{
1794+
cty.ObjectVal(map[string]cty.Value{
1795+
"foo": cty.StringVal("bar"),
1796+
"foo.bar": cty.StringVal("baz"),
1797+
}),
1798+
}),
1799+
})
1800+
diff := runDiffCheck(t, diffTestCase{
1801+
Resource: res,
1802+
Config1: initialValue,
1803+
Config2: changeValue,
1804+
})
1805+
1806+
autogold.ExpectFile(t, diffTestOutput{
1807+
initialValue: initialValue,
1808+
changeValue: changeValue,
1809+
tfOut: diff.TFOut,
1810+
pulumiOut: diff.PulumiOut,
1811+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1812+
})
1813+
})
1814+
1815+
t.Run("deleted", func(t *testing.T) {
1816+
initialValue := cty.ObjectVal(map[string]cty.Value{
1817+
"prop": cty.ListVal([]cty.Value{
1818+
cty.ObjectVal(map[string]cty.Value{
1819+
"foo": cty.StringVal("bar"),
1820+
"foo.bar": cty.StringVal("baz"),
1821+
}),
1822+
}),
1823+
})
1824+
changeValue := cty.ObjectVal(map[string]cty.Value{
1825+
"prop": cty.ListVal([]cty.Value{
1826+
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
1827+
}),
1828+
})
1829+
diff := runDiffCheck(t, diffTestCase{
1830+
Resource: res,
1831+
Config1: initialValue,
1832+
Config2: changeValue,
1833+
})
1834+
1835+
autogold.ExpectFile(t, diffTestOutput{
1836+
initialValue: initialValue,
1837+
changeValue: changeValue,
1838+
tfOut: diff.TFOut,
1839+
pulumiOut: diff.PulumiOut,
1840+
detailedDiff: diff.PulumiDiff.DetailedDiff,
1841+
})
1842+
})
1843+
})
1844+
}
1845+
}
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)