Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed diff tests for properties with dot in the name #2671

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/internal/tests/cross-tests/diff_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func runDiffCheck(t T, tc diffTestCase) crosstestsimpl.DiffResult {

resMap := map[string]*schema.Resource{defRtype: tc.Resource}
tfp := &schema.Provider{ResourcesMap: resMap}
bridgedProvider := pulcheck.BridgedProvider(t, defProviderShortName, tfp, pulcheck.EnableAccurateBridgePreviews())
opts := []pulcheck.BridgedProviderOpt{}
if os.Getenv("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW") != "false" {
opts = append(opts, pulcheck.EnableAccurateBridgePreviews())
}
bridgedProvider := pulcheck.BridgedProvider(t, defProviderShortName, tfp, opts...)
if tc.DeleteBeforeReplace {
bridgedProvider.Resources[defRtype].DeleteBeforeReplace = true
}
Expand Down
134 changes: 122 additions & 12 deletions pkg/internal/tests/cross-tests/diff_cross_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"hash/crc32"
"slices"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -1625,6 +1626,14 @@ func TestBlockCollectionElementForceNew(t *testing.T) {
})
}

type diffTestOutput struct {
initialValue cty.Value
changeValue cty.Value
tfOut string
pulumiOut string
detailedDiff map[string]any
}

func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
t.Parallel()
// TODO[pulumi/pulumi-terraform-bridge#2660]
Expand All @@ -1650,14 +1659,6 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
},
}

type testOutput struct {
initialValue cty.Value
changeValue cty.Value
tfOut string
pulumiOut string
detailedDiff map[string]any
}

t.Run("no change", func(t *testing.T) {
t.Parallel()
initialValue := cty.ObjectVal(map[string]cty.Value{})
Expand All @@ -1668,7 +1669,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
Config2: changeValue,
})

autogold.ExpectFile(t, testOutput{
autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
Expand All @@ -1687,7 +1688,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
Config2: changeValue,
})

autogold.ExpectFile(t, testOutput{
autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
Expand All @@ -1706,7 +1707,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
Config2: changeValue,
})

autogold.ExpectFile(t, testOutput{
autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
Expand All @@ -1725,7 +1726,7 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
Config2: changeValue,
})

autogold.ExpectFile(t, testOutput{
autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
Expand All @@ -1734,3 +1735,112 @@ func TestDetailedDiffReplacementComputedProperty(t *testing.T) {
})
})
}

func TestPropertyWithDot(t *testing.T) {
res := &schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"foo": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}

for _, accuratePreivewsEnabled := range []bool{true, false} {
t.Run(fmt.Sprintf("accuratePreivewsEnabled=%v", accuratePreivewsEnabled), func(t *testing.T) {
t.Setenv("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW", strconv.FormatBool(accuratePreivewsEnabled))
t.Run("unchanged", func(t *testing.T) {
initialValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
}),
})
changeValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{"foo.bar": cty.StringVal("baz")}),
}),
})
diff := runDiffCheck(t, diffTestCase{
Resource: res,
Config1: initialValue,
Config2: changeValue,
})

autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
pulumiOut: diff.PulumiOut,
detailedDiff: diff.PulumiDiff.DetailedDiff,
})
})

t.Run("added", func(t *testing.T) {
initialValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
}),
})
changeValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
"foo.bar": cty.StringVal("baz"),
}),
}),
})
diff := runDiffCheck(t, diffTestCase{
Resource: res,
Config1: initialValue,
Config2: changeValue,
})

autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
pulumiOut: diff.PulumiOut,
detailedDiff: diff.PulumiDiff.DetailedDiff,
})
})

t.Run("deleted", func(t *testing.T) {
initialValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
"foo.bar": cty.StringVal("baz"),
}),
}),
})
changeValue := cty.ObjectVal(map[string]cty.Value{
"prop": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("bar")}),
}),
})
diff := runDiffCheck(t, diffTestCase{
Resource: res,
Config1: initialValue,
Config2: changeValue,
})

autogold.ExpectFile(t, diffTestOutput{
initialValue: initialValue,
changeValue: changeValue,
tfOut: diff.TFOut,
pulumiOut: diff.PulumiOut,
detailedDiff: diff.PulumiDiff.DetailedDiff,
})
})
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
crosstests.diffTestOutput{
initialValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"prop": {
typeImpl: cty.typeList{ElementTypeT: cty.Type{
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
"foo": {typeImpl: cty.primitiveType{
Kind: cty.primitiveTypeKind(83),
}},
}},
}},
}},
}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
},
changeValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{
"foo": {
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
},
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
},
}},
}}}}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
"foo": "bar",
"foo.bar": "baz",
}}},
},
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
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
crosstests.diffTestOutput{
initialValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"prop": {
typeImpl: cty.typeList{ElementTypeT: cty.Type{
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
"foo": {typeImpl: cty.primitiveType{
Kind: cty.primitiveTypeKind(83),
}},
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
}},
}},
}},
}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
"foo": "bar",
"foo.bar": "baz",
}}},
},
changeValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"foo": {
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
}},
}},
}}}}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
},
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
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
crosstests.diffTestOutput{
initialValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"prop": {
typeImpl: cty.typeList{ElementTypeT: cty.Type{
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
"foo.bar": {typeImpl: cty.primitiveType{
Kind: cty.primitiveTypeKind(83),
}},
}},
}},
}},
}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo.bar": "baz"}}},
},
changeValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"foo.bar": {
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
}},
}},
}}}}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo.bar": "baz"}}},
},
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
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
crosstests.diffTestOutput{
initialValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{"prop": {
typeImpl: cty.typeList{ElementTypeT: cty.Type{
typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{
"foo": {typeImpl: cty.primitiveType{
Kind: cty.primitiveTypeKind(83),
}},
}},
}},
}},
}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{"foo": "bar"}}},
},
changeValue: cty.Value{
ty: cty.Type{typeImpl: cty.typeObject{AttrTypes: map[string]cty.Type{"prop": {typeImpl: cty.typeList{
ElementTypeT: cty.Type{typeImpl: cty.typeObject{
AttrTypes: map[string]cty.Type{
"foo": {
typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)},
},
"foo.bar": {typeImpl: cty.primitiveType{Kind: cty.primitiveTypeKind(83)}},
},
}},
}}}}},
v: map[string]interface{}{"prop": []interface{}{map[string]interface{}{
"foo": "bar",
"foo.bar": "baz",
}}},
},
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
Loading