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

Enable PRC by default #2380

Merged
merged 43 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6a81da1
expand diff cross tests
VenelinMartinov Aug 26, 2024
f4de62c
verify order on replace
VenelinMartinov Aug 26, 2024
aafaaf8
add test cases
VenelinMartinov Aug 26, 2024
0b26e14
handle empty config
VenelinMartinov Aug 26, 2024
cc8af17
add tf action assertions
VenelinMartinov Aug 27, 2024
44cb678
detailed diff cross tests
VenelinMartinov Aug 27, 2024
ab4ec43
Merge branch 'master' into vvm/collection_only_detailed_diff_cross_test
VenelinMartinov Aug 30, 2024
8141c84
lint
VenelinMartinov Aug 30, 2024
e679a79
assert TF before and after not equal
VenelinMartinov Aug 30, 2024
ffe9d31
PRC test cleanup
VenelinMartinov Aug 30, 2024
32ea39f
Merge branch 'vvm/collection_only_detailed_diff_cross_test' into vvm/…
VenelinMartinov Aug 30, 2024
0208e84
skip panic test for now
VenelinMartinov Aug 30, 2024
06137ea
skip test
VenelinMartinov Aug 30, 2024
2e23036
fix test
VenelinMartinov Aug 30, 2024
174d0c0
fix test
VenelinMartinov Aug 30, 2024
133ae0a
accidental change
VenelinMartinov Aug 30, 2024
34a0bef
skip deceptive tests
VenelinMartinov Aug 30, 2024
b637050
re-record test
VenelinMartinov Sep 3, 2024
2ccf2fc
separate v1 and v2 tests
VenelinMartinov Sep 3, 2024
06a73a3
lint
VenelinMartinov Sep 3, 2024
ea5fd70
ignore set order in test
VenelinMartinov Sep 3, 2024
360deff
fix provider test panics
VenelinMartinov Sep 3, 2024
b8b22e3
add back PRC opt out
VenelinMartinov Sep 3, 2024
fac7d64
skip some more tests
VenelinMartinov Sep 3, 2024
7c39bb0
fix some more GRPC tests
VenelinMartinov Sep 3, 2024
fdb54f6
more GRPC test fixes
VenelinMartinov Sep 3, 2024
a174362
Merge branch 'master' into vvm/collection_only_detailed_diff_cross_test
VenelinMartinov Sep 16, 2024
4eb2b84
Merge branch 'vvm/collection_only_detailed_diff_cross_test' into vvm/…
VenelinMartinov Sep 16, 2024
e224aac
Merge branch 'master' into vvm/collection_only_detailed_diff_cross_test
VenelinMartinov Sep 16, 2024
551a615
Merge branch 'vvm/collection_only_detailed_diff_cross_test' into vvm/…
VenelinMartinov Sep 16, 2024
d893052
fix test
VenelinMartinov Sep 16, 2024
66bcd25
remove panic tests for type checker
VenelinMartinov Sep 17, 2024
0c97572
fix state internals tests
VenelinMartinov Sep 17, 2024
0755a9c
Merge branch 'master' into vvm/PRC_cleanup
VenelinMartinov Sep 17, 2024
a6a081d
fix grpc test
VenelinMartinov Sep 17, 2024
8983d73
add back deleted tests, add integration test
VenelinMartinov Sep 18, 2024
21098e8
correct test naming
VenelinMartinov Sep 18, 2024
023f2aa
correct expected output, add testing.T to subtests
VenelinMartinov Sep 18, 2024
0b70e85
Merge branch 'master' into vvm/PRC_cleanup
VenelinMartinov Sep 19, 2024
32f6385
allow disabling PRC
VenelinMartinov Sep 19, 2024
c6614da
add todos for unknown elements in sets
VenelinMartinov Sep 19, 2024
5da8c78
remove debug fails
VenelinMartinov Sep 19, 2024
aae1f19
correct issue number
VenelinMartinov Sep 19, 2024
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
3 changes: 2 additions & 1 deletion pf/tests/provider_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func TestMuxedAliasCreate(t *testing.T) {
"id": "4",
"fair": true,
"number": 4,
"suggestionUpdated": false
"suggestionUpdated": false,
"suggestion": "*"
}
},
"metadata": {
Expand Down
13 changes: 2 additions & 11 deletions pkg/tests/regress_1020_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func TestRegress1020(t *testing.T) {
"addresses": [
"2001:0db8:85a3:0000:0000:8a2e:0370:7334/32"
],
"id": "",
"id": "04da6b54-80e4-46f7-96ec-b56ff0331ba9",
"rules": [],
"ipAddressVersion": "IPV6",
"name": "ip6_sample-e8442ad",
"scope": "CLOUDFRONT"
Expand All @@ -201,11 +202,6 @@ func TestRegress1020(t *testing.T) {
testutils.Replay(t, server(p), createTestCase)
})

t.Run("can preview Create when using PlanState", func(t *testing.T) {
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState))
testutils.Replay(t, server(p), createTestCase)
})

diffTestCase := `
{
"method": "/pulumirpc.ResourceProvider/Diff",
Expand Down Expand Up @@ -250,9 +246,4 @@ func TestRegress1020(t *testing.T) {
p := shimv2.NewProvider(tfProvider)
testutils.Replay(t, server(p), diffTestCase)
})

t.Run("can compute an Update plan in Diff when using PlanState", func(t *testing.T) {
p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState))
testutils.Replay(t, server(p), diffTestCase)
})
}
5 changes: 4 additions & 1 deletion pkg/tests/regress_hcloud_175_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ func TestRegressHCloud175(t *testing.T) {
"id": "*",
"ipRange": "10.0.1.0/24",
"networkZone": "eu-central",
"type": "cloud"
"type": "cloud",
"gateway": "*",
"vswitchId": "*",
"networkId": "*"
}
}
}`
Expand Down
124 changes: 124 additions & 0 deletions pkg/tests/schema_pulumi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4199,3 +4199,127 @@ outputs:
assert.Equal(t, "val", out.Outputs["keyValue"].Value)
assert.Equal(t, "", out.Outputs["emptyValue"].Value)
}

func TestUnknownSetElementDiff(t *testing.T) {
resMap := map[string]*schema.Resource{
"prov_test": {
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
"prov_aux": {
Schema: map[string]*schema.Schema{
"aux": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
},
CreateContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
d.SetId("aux")
err := d.Set("aux", "aux")
require.NoError(t, err)
return nil
},
},
}
tfp := &schema.Provider{ResourcesMap: resMap}

runTest := func(t *testing.T, PRC bool, expectedOutput autogold.Value) {
opts := []pulcheck.BridgedProviderOpt{}
if !PRC {
opts = append(opts, pulcheck.DisablePlanResourceChange())
}
bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp, opts...)
originalProgram := `
name: test
runtime: yaml
resources:
mainRes:
type: prov:index:Test
outputs:
testOut: ${mainRes.tests}
`

programWithUnknown := `
name: test
runtime: yaml
resources:
auxRes:
type: prov:index:Aux
mainRes:
type: prov:index:Test
properties:
tests:
- ${auxRes.aux}
outputs:
testOut: ${mainRes.tests}
`
pt := pulcheck.PulCheck(t, bridgedProvider, originalProgram)
pt.Up()
pulumiYamlPath := filepath.Join(pt.CurrentStack().Workspace().WorkDir(), "Pulumi.yaml")

err := os.WriteFile(pulumiYamlPath, []byte(programWithUnknown), 0o600)
require.NoError(t, err)

res := pt.Preview(optpreview.Diff())
// Test that the test property is unknown at preview time
expectedOutput.Equal(t, res.StdOut)
resUp := pt.Up()
// assert that the property gets resolved
require.Equal(t,
[]interface{}{"aux"},
resUp.Outputs["testOut"].Value,
)
}

t.Run("PRC enabled", func(t *testing.T) {
// TODO[pulumi/pulumi-terraform-bridge#2427]: Incorrect detailed diff with unknown elements
t.Skip("Skipping until pulumi/pulumi-terraform-bridge#2427 is resolved")
runTest(t, true, autogold.Expect(`Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::test::pulumi:pulumi:Stack::test-test]
+ prov:index/aux:Aux: (create)
[urn=urn:pulumi:test::test::prov:index/aux:Aux::auxRes]
~ prov:index/test:Test: (update)
[id=newid]
[urn=urn:pulumi:test::test::prov:index/test:Test::mainRes]
+ tests: [
+ [0]: output<string>
]
--outputs:--
+ testOut: output<string>
Resources:
+ 1 to create
~ 1 to update
2 changes. 1 unchanged
`))
})

t.Run("PRC disabled", func(t *testing.T) {
runTest(t, false, autogold.Expect(`Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::test::pulumi:pulumi:Stack::test-test]
+ prov:index/aux:Aux: (create)
[urn=urn:pulumi:test::test::prov:index/aux:Aux::auxRes]
~ prov:index/test:Test: (update)
[id=newid]
[urn=urn:pulumi:test::test::prov:index/test:Test::mainRes]
+ tests: [
+ [0]: output<string>
]
--outputs:--
+ testOut: output<string>
Resources:
+ 1 to create
~ 1 to update
2 changes. 1 unchanged
`))
})
}
27 changes: 17 additions & 10 deletions pkg/tfbridge/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ func TestCustomizeDiff(t *testing.T) {
return err
},
}
provider := shimv2.NewProvider(&v2Schema.Provider{
v2Provider := v2Schema.Provider{
ResourcesMap: map[string]*v2Schema.Resource{
"resource": customDiffRes,
},
})
}
provider := shimv2.NewProvider(&v2Provider)

// Convert the inputs and state to TF config and resource attributes.
r := Resource{
TF: shimv2.NewResource(customDiffRes),
TF: provider.ResourcesMap().Get("resource"),
Schema: &ResourceInfo{Fields: info},
}
tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
Expand Down Expand Up @@ -118,15 +119,16 @@ func TestCustomizeDiff(t *testing.T) {
noCustomDiffRes := &v2Schema.Resource{
Schema: tfs,
}
provider := shimv2.NewProvider(&v2Schema.Provider{
v2Provider := v2Schema.Provider{
ResourcesMap: map[string]*v2Schema.Resource{
"resource": noCustomDiffRes,
},
})
}
provider := shimv2.NewProvider(&v2Provider)

// Convert the inputs and state to TF config and resource attributes.
r := Resource{
TF: shimv2.NewResource(noCustomDiffRes),
TF: provider.ResourcesMap().Get("resource"),
Schema: &ResourceInfo{Fields: info},
}
tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
Expand Down Expand Up @@ -180,7 +182,7 @@ func TestCustomizeDiff(t *testing.T) {

// Convert the inputs and state to TF config and resource attributes.
r := Resource{
TF: shimv2.NewResource(customDiffRes),
TF: provider.ResourcesMap().Get("resource"),
Schema: &ResourceInfo{Fields: info},
}
tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
Expand Down Expand Up @@ -245,16 +247,17 @@ func v2Setup(tfs map[string]*v2Schema.Schema) (
return d.SetNewComputed("outp")
},
}
provider := shimv2.NewProvider(&v2Schema.Provider{
v2Provider := v2Schema.Provider{
ResourcesMap: map[string]*v2Schema.Resource{
"resource": res,
},
})
}
provider := shimv2.NewProvider(&v2Provider)
info := map[string]*SchemaInfo{}

// Convert the inputs and state to TF config and resource attributes.
r := Resource{
TF: shimv2.NewResource(res),
TF: provider.ResourcesMap().Get("resource"),
Schema: &ResourceInfo{Fields: info},
}

Expand Down Expand Up @@ -1464,6 +1467,8 @@ func TestNestedComputedSetUpdate(t *testing.T) {
}

func TestNestedComputedSetAdd(t *testing.T) {
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
// TODO[pulumi/pulumi-terraform-bridge#2427]: Incorrect detailed diff with unknown elements
t.Skip("Skipping until pulumi/pulumi-terraform-bridge#2427 is resolved")
diffTest(t,
map[string]*v2Schema.Schema{
"prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}},
Expand Down Expand Up @@ -1539,6 +1544,8 @@ func TestNestedComputedSetIntUpdateReplace(t *testing.T) {
}

func TestNestedComputedSetIntAdd(t *testing.T) {
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
// TODO[pulumi/pulumi-terraform-bridge#2427]: Incorrect detailed diff with unknown elements
t.Skip("Skipping until pulumi/pulumi-terraform-bridge#2427 is resolved")
diffTest(t,
map[string]*v2Schema.Schema{
"prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeInt}},
Expand Down
Loading