2022-01-11 17:20:43 +00:00
|
|
|
package lifecycletest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
[engine] Add support for source positions
These changes add support for passing source position information in
gRPC metadata and recording the source position that corresponds to a
resource registration in the statefile.
Enabling source position information in the resource model can provide
substantial benefits, including but not limited to:
- Better errors from the Pulumi CLI
- Go-to-defintion for resources in state
- Editor integration for errors, etc. from `pulumi preview`
Source positions are (file, line) or (file, line, column) tuples
represented as URIs. The line and column are stored in the fragment
portion of the URI as "line(,column)?". The scheme of the URI and the
form of its path component depends on the context in which it is
generated or used:
- During an active update, the URI's scheme is `file` and paths are
absolute filesystem paths. This allows consumers to easily access
arbitrary files that are available on the host.
- In a statefile, the URI's scheme is `project` and paths are relative
to the project root. This allows consumers to resolve source positions
relative to the project file in different contexts irrespective of the
location of the project itself (e.g. given a project-relative path and
the URL of the project's root on GitHub, one can build a GitHub URL for
the source position).
During an update, source position information may be attached to gRPC
calls as "source-position" metadata. This allows arbitrary calls to be
associated with source positions without changes to their protobuf
payloads. Modifying the protobuf payloads is also a viable approach, but
is somewhat more invasive than attaching metadata, and requires changes
to every call signature.
Source positions should reflect the position in user code that initiated
a resource model operation (e.g. the source position passed with
`RegisterResource` for `pet` in the example above should be the source
position in `index.ts`, _not_ the source position in the Pulumi SDK). In
general, the Pulumi SDK should be able to infer the source position of
the resource registration, as the relationship between a resource
registration and its corresponding user code should be static per SDK.
Source positions in state files will be stored as a new `registeredAt`
property on each resource. This property is optional.
2023-06-29 18:41:19 +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{
|
|
|
|
CreateF: func(urn resource.URN, inputs resource.PropertyMap, timeout float64,
|
|
|
|
preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
|
|
|
// Return the secret value as an unmasked output. This should get masked by the engine.
|
|
|
|
return "id", resource.PropertyMap{
|
|
|
|
"shouldBeSecret": resource.NewStringProperty("bar"),
|
|
|
|
}, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}, 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{
|
|
|
|
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64, preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
|
|
|
return "created-id", news, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
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{
|
|
|
|
ReadF: func(urn resource.URN, id resource.ID, inputs, state resource.PropertyMap,
|
|
|
|
) (plugin.ReadResult, resource.Status, error) {
|
|
|
|
return plugin.ReadResult{Outputs: resource.PropertyMap{}}, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", "read-id", "", nil, "", "", "")
|
|
|
|
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{
|
|
|
|
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64,
|
|
|
|
preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
|
|
|
// Should match the ReadResource resource ID.
|
|
|
|
return resourceID, news, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
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{
|
|
|
|
ReadF: func(urn resource.URN, id resource.ID,
|
|
|
|
inputs, state resource.PropertyMap,
|
|
|
|
) (plugin.ReadResult, resource.Status, error) {
|
|
|
|
return plugin.ReadResult{
|
|
|
|
Outputs: resource.PropertyMap{},
|
|
|
|
}, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", resourceID, "", nil, "", "", "")
|
|
|
|
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{
|
|
|
|
ReadF: func(urn resource.URN, id resource.ID,
|
|
|
|
inputs, state resource.PropertyMap,
|
|
|
|
) (plugin.ReadResult, resource.Status, error) {
|
|
|
|
return plugin.ReadResult{
|
|
|
|
Outputs: resource.PropertyMap{},
|
|
|
|
}, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", "my-resource-id", "", nil, "", "", "")
|
|
|
|
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{
|
|
|
|
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64,
|
|
|
|
preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
|
|
|
// Should match the ReadF resource ID.
|
|
|
|
return "my-resource-id", news, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
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{
|
|
|
|
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64,
|
|
|
|
preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
|
|
|
return "my-resource-id", news, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
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{
|
|
|
|
ReadF: func(urn resource.URN, id resource.ID,
|
|
|
|
inputs, state resource.PropertyMap,
|
|
|
|
) (plugin.ReadResult, resource.Status, error) {
|
|
|
|
return plugin.ReadResult{}, resource.StatusOK, nil
|
|
|
|
},
|
|
|
|
}).
|
|
|
|
RunUpdate(func(info plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
|
|
|
_, _, err := monitor.ReadResource("pkgA:m:typA", "resA", resourceID, "", nil, "", "", "")
|
|
|
|
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")
|
|
|
|
})
|
|
|
|
}
|