pulumi/pkg/engine/update_test.go

97 lines
2.7 KiB
Go
Raw Permalink Normal View History

package engine
import (
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
"context"
"path/filepath"
"testing"
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/pkg/v3/util/cancel"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/stretchr/testify/assert"
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
"github.com/stretchr/testify/require"
)
func TestAbbreviateFilePath(t *testing.T) {
t.Parallel()
tests := []struct {
path string
expected string
}{
{
path: "/Users/username/test-policy",
expected: "/Users/username/test-policy",
},
{
path: "./..//test-policy",
expected: "../test-policy",
},
{
path: `/Users/username/averylongpath/one/two/three/four/` +
`five/six/seven/eight/nine/ten/eleven/twelve/test-policy`,
expected: "/Users/.../twelve/test-policy",
},
{
path: `nonrootdir/username/averylongpath/one/two/three/four/` +
`five/six/seven/eight/nine/ten/eleven/twelve/test-policy`,
expected: "nonrootdir/username/.../twelve/test-policy",
},
{
path: `C:/Documents and Settings/username/My Documents/averylongpath/` +
`one/two/three/four/five/six/seven/eight/test-policy`,
expected: "C:/Documents and Settings/.../eight/test-policy",
},
{
path: `C:\Documents and Settings\username\My Documents\averylongpath\` +
`one\two\three\four\five\six\seven\eight\test-policy`,
expected: `C:\Documents and Settings\...\eight\test-policy`,
},
}
for _, tt := range tests {
actual := abbreviateFilePath(tt.path)
assert.Equal(t, filepath.ToSlash(tt.expected), filepath.ToSlash(actual))
}
}
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
func TestDeletingComponentResourceProducesResourceOutputsEvent(t *testing.T) {
t.Parallel()
cancelCtx, _ := cancel.NewContext(context.Background())
acts := newUpdateActions(&Context{
Cancel: cancelCtx,
}, nil, &deploymentOptions{})
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
eventsChan := make(chan Event, 10)
acts.Opts.Events.ch = eventsChan
step := deploy.NewDeleteStep(&deploy.Deployment{}, map[resource.URN]bool{}, &resource.State{
URN: resource.URN("urn:pulumi:stack::project::my:example:Foo::foo"),
ID: "foo",
Custom: false,
Provider: "unimportant",
})
acts.Seen[resource.URN("urn:pulumi:stack::project::my:example:Foo::foo")] = step
err := acts.OnResourceStepPost(
&mockSnapshotMutation{}, step, resource.StatusOK,
nil, /* err */
)
require.NoError(t, err)
turn on the golangci-lint exhaustive linter (#15028) Turn on the golangci-lint exhaustive linter. This is the first step towards catching more missing cases during development rather than in tests, or in production. This might be best reviewed commit-by-commit, as the first commit turns on the linter with the `default-signifies-exhaustive: true` option set, which requires a lot less changes in the current codebase. I think it's probably worth doing the second commit as well, as that will get us the real benefits, even though we end up with a little bit more churn. However it means all the `switch` statements are covered, which isn't the case after the first commit, since we do have a lot of `default` statements that just call `assert.Fail`. Fixes #14601 ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-01-17 16:50:41 +00:00
//nolint:exhaustive // the default case is for test failures
[display] fix ComponentResource deletion not stopping time elapsed timer (#14061) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #13357 ComponentResources now emit resourceOutputEvent on delete steps. This fixes the time elapsed timer not stopping when the resource is deleted. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-09-29 19:48:33 +00:00
switch e := <-eventsChan; e.Type {
case ResourceOutputsEvent:
e, ok := e.Payload().(ResourceOutputsEventPayload)
assert.True(t, ok)
assert.True(t, e.Metadata.URN == "urn:pulumi:stack::project::my:example:Foo::foo")
default:
assert.Fail(t, "unexpected event type")
}
}
type mockSnapshotMutation struct{}
func (msm *mockSnapshotMutation) End(step deploy.Step, successful bool) error { return nil }