2022-01-11 17:20:43 +00:00
|
|
|
package lifecycletest
|
|
|
|
|
|
|
|
import (
|
2024-07-26 12:14:45 +00:00
|
|
|
"context"
|
2022-01-11 17:20:43 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/blang/semver"
|
2023-11-21 15:16:13 +00:00
|
|
|
. "github.com/pulumi/pulumi/pkg/v3/engine" //nolint:revive
|
2023-12-10 21:29:37 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
|
2022-01-11 17:20:43 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestDuplicateURN tests that duplicate URNs are disallowed.
|
|
|
|
func TestDuplicateURN(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-01-11 17:20:43 +00:00
|
|
|
loaders := []*deploytest.ProviderLoader{
|
|
|
|
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
|
|
|
return &deploytest.Provider{}, nil
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2023-09-28 21:50:18 +00:00
|
|
|
programF := deploytest.NewLanguageRuntimeF(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2022-01-11 17:20:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err = monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2022-01-11 17:20:43 +00:00
|
|
|
assert.Error(t, err)
|
2022-05-24 15:08:17 +00:00
|
|
|
|
|
|
|
// Reads use the same URN namespace as register so make sure this also errors
|
2024-07-26 10:03:18 +00:00
|
|
|
_, _, err = monitor.ReadResource("pkgA:m:typA", "resA", "id", "", resource.PropertyMap{}, "", "", "", "")
|
2022-05-24 15:08:17 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2022-01-11 17:20:43 +00:00
|
|
|
return nil
|
|
|
|
})
|
2023-09-28 21:50:18 +00:00
|
|
|
hostF := deploytest.NewPluginHostF(nil, nil, programF, loaders...)
|
2022-01-11 17:20:43 +00:00
|
|
|
|
|
|
|
p := &TestPlan{
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
Options: TestUpdateOptions{T: t, HostF: hostF},
|
2022-01-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
project := p.GetProject()
|
2023-10-11 14:44:09 +00:00
|
|
|
_, err := TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient, nil)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.Error(t, err)
|
2022-01-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestDuplicateAlias tests that multiple new resources may not claim to be aliases for the same old resource.
|
|
|
|
func TestDuplicateAlias(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-01-11 17:20:43 +00:00
|
|
|
loaders := []*deploytest.ProviderLoader{
|
|
|
|
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
|
|
|
return &deploytest.Provider{}, nil
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
program := func(monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2022-01-11 17:20:43 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-28 21:50:18 +00:00
|
|
|
runtimeF := deploytest.NewLanguageRuntimeF(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2022-01-11 17:20:43 +00:00
|
|
|
return program(monitor)
|
|
|
|
})
|
2023-09-28 21:50:18 +00:00
|
|
|
hostF := deploytest.NewPluginHostF(nil, nil, runtimeF, loaders...)
|
2022-01-11 17:20:43 +00:00
|
|
|
|
|
|
|
p := &TestPlan{
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
Options: TestUpdateOptions{T: t, HostF: hostF},
|
2022-01-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
resURN := p.NewURN("pkgA:m:typA", "resA", "")
|
|
|
|
|
|
|
|
project := p.GetProject()
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
snap, err := TestOp(Update).RunStep(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient, nil, "0")
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2022-01-11 17:20:43 +00:00
|
|
|
|
|
|
|
program = func(monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resB", true, deploytest.ResourceOptions{
|
2022-09-21 19:42:24 +00:00
|
|
|
AliasURNs: []resource.URN{resURN},
|
2022-01-11 17:20:43 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err = monitor.RegisterResource("pkgA:m:typA", "resC", true, deploytest.ResourceOptions{
|
2022-09-21 19:42:24 +00:00
|
|
|
AliasURNs: []resource.URN{resURN},
|
2022-01-11 17:20:43 +00:00
|
|
|
})
|
|
|
|
assert.Error(t, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
_, err = TestOp(Update).RunStep(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient, nil, "1")
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.Error(t, err)
|
2022-01-11 17:20:43 +00:00
|
|
|
}
|
2023-06-23 16:17:01 +00:00
|
|
|
|
|
|
|
func TestSecretMasked(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
loaders := []*deploytest.ProviderLoader{
|
|
|
|
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
|
|
|
return &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
CreateF: func(_ context.Context, req plugin.CreateRequest) (plugin.CreateResponse, error) {
|
2023-06-23 16:17:01 +00:00
|
|
|
// Return the secret value as an unmasked output. This should get masked by the engine.
|
2024-07-26 12:14:45 +00:00
|
|
|
return plugin.CreateResponse{
|
|
|
|
ID: "id",
|
|
|
|
Properties: resource.PropertyMap{
|
|
|
|
"shouldBeSecret": resource.NewStringProperty("bar"),
|
|
|
|
},
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-06-23 16:17:01 +00:00
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2023-09-28 21:50:18 +00:00
|
|
|
programF := deploytest.NewLanguageRuntimeF(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true, deploytest.ResourceOptions{
|
2023-06-23 16:17:01 +00:00
|
|
|
Inputs: resource.PropertyMap{
|
|
|
|
"shouldBeSecret": resource.MakeSecret(resource.NewStringProperty("bar")),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2023-09-28 21:50:18 +00:00
|
|
|
hostF := deploytest.NewPluginHostF(nil, nil, programF, loaders...)
|
2023-06-23 16:17:01 +00:00
|
|
|
|
|
|
|
p := &TestPlan{
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
// Skip display tests because secrets are serialized with the blinding crypter and can't be restored
|
|
|
|
Options: TestUpdateOptions{T: t, HostF: hostF, SkipDisplayTests: true},
|
2023-06-23 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
project := p.GetProject()
|
2023-10-11 14:44:09 +00:00
|
|
|
snap, err := TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient, nil)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-06-23 16:17:01 +00:00
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
if snap != nil {
|
|
|
|
assert.True(t, snap.Resources[1].Outputs["shouldBeSecret"].IsSecret())
|
|
|
|
}
|
|
|
|
}
|
2023-12-10 21:29:37 +00:00
|
|
|
|
|
|
|
// TestReadReplaceStep creates a resource and then replaces it with a read resource.
|
|
|
|
func TestReadReplaceStep(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// Create resource.
|
|
|
|
newTestBuilder(t, nil).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
CreateF: func(_ context.Context, req plugin.CreateRequest) (plugin.CreateResponse, error) {
|
|
|
|
return plugin.CreateResponse{
|
|
|
|
ID: "created-id",
|
|
|
|
Properties: req.Properties,
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, true).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.False(t, snap.Resources[1].External)
|
|
|
|
|
|
|
|
// ReadReplace resource.
|
|
|
|
newTestBuilder(t, snap).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
ReadF: func(_ context.Context, req plugin.ReadRequest) (plugin.ReadResponse, error) {
|
|
|
|
return plugin.ReadResponse{
|
|
|
|
ReadResult: plugin.ReadResult{Outputs: resource.PropertyMap{}},
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-07-26 10:03:18 +00:00
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", "read-id", "", nil, "", "", "", "")
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, false).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.True(t, snap.Resources[1].External)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRelinquishStep(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const resourceID = "my-resource-id"
|
|
|
|
newTestBuilder(t, nil).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
CreateF: func(_ context.Context, req plugin.CreateRequest) (plugin.CreateResponse, error) {
|
2023-12-10 21:29:37 +00:00
|
|
|
// Should match the ReadResource resource ID.
|
2024-07-26 12:14:45 +00:00
|
|
|
return plugin.CreateResponse{
|
|
|
|
ID: resourceID,
|
|
|
|
Properties: req.Properties,
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, true).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.False(t, snap.Resources[1].External)
|
|
|
|
|
|
|
|
newTestBuilder(t, snap).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
ReadF: func(_ context.Context, req plugin.ReadRequest) (plugin.ReadResponse, error) {
|
|
|
|
return plugin.ReadResponse{
|
|
|
|
ReadResult: plugin.ReadResult{Outputs: resource.PropertyMap{}},
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-07-26 10:03:18 +00:00
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", resourceID, "", nil, "", "", "", "")
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, true).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.True(t, snap.Resources[1].External)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTakeOwnershipStep(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
newTestBuilder(t, nil).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
ReadF: func(_ context.Context, req plugin.ReadRequest) (plugin.ReadResponse, error) {
|
|
|
|
return plugin.ReadResponse{
|
|
|
|
ReadResult: plugin.ReadResult{Outputs: resource.PropertyMap{}},
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-07-26 10:03:18 +00:00
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", "my-resource-id", "", nil, "", "", "", "")
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, false).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.True(t, snap.Resources[1].External)
|
|
|
|
|
|
|
|
// Create new resource for this snapshot.
|
|
|
|
newTestBuilder(t, snap).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
CreateF: func(_ context.Context, req plugin.CreateRequest) (plugin.CreateResponse, error) {
|
2023-12-10 21:29:37 +00:00
|
|
|
// Should match the ReadF resource ID.
|
2024-07-26 12:14:45 +00:00
|
|
|
return plugin.CreateResponse{
|
|
|
|
ID: "my-resource-id",
|
|
|
|
Properties: req.Properties,
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, true).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.False(t, snap.Resources[1].External)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInitErrorsStep(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// Create new resource for this snapshot.
|
|
|
|
newTestBuilder(t, &deploy.Snapshot{
|
|
|
|
Resources: []*resource.State{
|
|
|
|
{
|
|
|
|
Type: "pulumi:providers:pkgA",
|
|
|
|
URN: "urn:pulumi:test::test::pulumi:providers:pkgA::default",
|
|
|
|
Custom: true,
|
|
|
|
Delete: false,
|
|
|
|
ID: "935b2216-aec5-4810-96fd-5f6eae57ac88",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "pkgA:m:typA",
|
|
|
|
URN: "urn:pulumi:test::test::pkgA:m:typA::resA",
|
|
|
|
Custom: true,
|
|
|
|
ID: "my-resource-id",
|
|
|
|
Provider: "urn:pulumi:test::test::pulumi:providers:pkgA::default::935b2216-aec5-4810-96fd-5f6eae57ac88",
|
|
|
|
InitErrors: []string{
|
|
|
|
`errors should yield an empty update to "continue" awaiting initialization.`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
CreateF: func(_ context.Context, req plugin.CreateRequest) (plugin.CreateResponse, error) {
|
|
|
|
return plugin.CreateResponse{
|
|
|
|
ID: "my-resource-id",
|
|
|
|
Properties: req.Properties,
|
|
|
|
Status: resource.StatusOK,
|
|
|
|
}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-04-19 11:08:56 +00:00
|
|
|
_, err := monitor.RegisterResource("pkgA:m:typA", "resA", true)
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, false).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NotNil(t, snap)
|
|
|
|
assert.Nil(t, snap.VerifyIntegrity())
|
|
|
|
assert.Len(t, snap.Resources, 2)
|
|
|
|
assert.Equal(t, resource.URN("urn:pulumi:test::test::pkgA:m:typA::resA"), snap.Resources[1].URN)
|
|
|
|
assert.Empty(t, snap.Resources[1].InitErrors)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadNilOutputs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const resourceID = "my-resource-id"
|
|
|
|
newTestBuilder(t, nil).
|
|
|
|
WithProvider("pkgA", "1.0.0", &deploytest.Provider{
|
2024-07-26 12:14:45 +00:00
|
|
|
ReadF: func(_ context.Context, req plugin.ReadRequest) (plugin.ReadResponse, error) {
|
|
|
|
return plugin.ReadResponse{}, nil
|
2023-12-10 21:29:37 +00:00
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
2024-07-26 10:03:18 +00:00
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", resourceID, "", nil, "", "", "", "")
|
2023-12-10 21:29:37 +00:00
|
|
|
assert.ErrorContains(t, err, "resource 'my-resource-id' does not exist")
|
|
|
|
|
|
|
|
return nil
|
Add display to the engine tests (#16050)
We want to add more test coverage to the display code. The best way to
do that is to add it to the engine tests, that already cover most of the
pulumi functionality.
It's probably not really possible to review all of the output, but at
least it gives us a baseline, which we can work with.
There's a couple of tests that are flaky for reasons I don't quite
understand yet. I marked them as to skip and we can look at them later.
I'd rather get in the baseline tests sooner, rather than spending a
bunch of time looking at that. The output differences also seem very
minor, so not super concerning.
The biggest remaining issue is that this doesn't interact well with the
Chdir we're doing in the engine. We could either pass the CWD through,
or just try to get rid of that Chdir. So this should only be merged
after https://github.com/pulumi/pulumi/pull/15607.
I've tried to split this into a few commits, separating out adding the
testdata, so it's hopefully a little easier to review, even though the
PR is still quite large.
One other thing to note is that we're comparing that the output has all
the same lines, and not that it is exactly the same. Because of how the
engine is implemented, there's a bunch of race conditions otherwise,
that would make us have to skip a bunch of tests, just because e.g.
resource A is sometimes deleted before resource B and sometimes it's the
other way around.
The biggest downside of that is that running with `PULUMI_ACCEPT` will
produce a diff even when there are no changes. Hopefully we won't have
to run that way too often though, so it might not be a huge issue?
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-05-13 07:18:25 +00:00
|
|
|
}, true).
|
2023-12-10 21:29:37 +00:00
|
|
|
Then(func(snap *deploy.Snapshot, err error) {
|
|
|
|
assert.ErrorContains(t, err,
|
|
|
|
"BAIL: step executor errored: step application failed: resource 'my-resource-id' does not exist")
|
|
|
|
})
|
|
|
|
}
|