Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
// Copyright 2016-2023, Pulumi Corporation.
|
2021-11-30 20:25:27 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-07-31 16:39:07 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
2023-06-21 20:46:36 +00:00
|
|
|
"runtime"
|
2019-07-31 16:39:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-11-30 20:25:27 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
|
2023-12-22 21:14:04 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
2021-07-13 14:39:48 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
|
Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
2019-07-31 16:39:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIgnoreChanges(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-07-31 16:39:07 +00:00
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
oldInputs map[string]interface{}
|
|
|
|
newInputs map[string]interface{}
|
|
|
|
expected map[string]interface{}
|
|
|
|
ignoreChanges []string
|
|
|
|
expectFailure bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Present in old and new sets",
|
|
|
|
oldInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "bar",
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
ignoreChanges: []string{"a.b"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Missing in new sets",
|
|
|
|
oldInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
ignoreChanges: []string{"a.b"},
|
|
|
|
},
|
2023-12-01 19:35:37 +00:00
|
|
|
{
|
|
|
|
name: "Present in old and new sets, using [\"\"]",
|
|
|
|
oldInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
ignoreChanges: []string{"a.b[\"c\"]"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Missing in new sets, using [\"\"]",
|
|
|
|
oldInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{},
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
ignoreChanges: []string{"a.b[\"c\"]"},
|
|
|
|
},
|
2019-07-31 16:39:07 +00:00
|
|
|
{
|
|
|
|
name: "Missing in old deletes",
|
|
|
|
oldInputs: map[string]interface{}{},
|
|
|
|
newInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{},
|
|
|
|
"c": 42,
|
|
|
|
},
|
|
|
|
ignoreChanges: []string{"a.b"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Missing keys in old and new are OK",
|
|
|
|
oldInputs: map[string]interface{}{},
|
|
|
|
newInputs: map[string]interface{}{},
|
|
|
|
ignoreChanges: []string{
|
|
|
|
"a",
|
|
|
|
"a.b",
|
|
|
|
"a.c[0]",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Missing parent keys in only new fail",
|
|
|
|
oldInputs: map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
newInputs: map[string]interface{}{},
|
|
|
|
ignoreChanges: []string{"a.b"},
|
|
|
|
expectFailure: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2022-03-04 08:17:41 +00:00
|
|
|
c := c
|
2019-07-31 16:39:07 +00:00
|
|
|
t.Run(c.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-07-31 16:39:07 +00:00
|
|
|
olds, news := resource.NewPropertyMapFromMap(c.oldInputs), resource.NewPropertyMapFromMap(c.newInputs)
|
|
|
|
|
|
|
|
expected := olds
|
|
|
|
if c.expected != nil {
|
|
|
|
expected = resource.NewPropertyMapFromMap(c.expected)
|
|
|
|
}
|
|
|
|
|
2023-10-13 09:46:07 +00:00
|
|
|
processed, err := processIgnoreChanges(news, olds, c.ignoreChanges)
|
2019-07-31 16:39:07 +00:00
|
|
|
if c.expectFailure {
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.Error(t, err)
|
2019-07-31 16:39:07 +00:00
|
|
|
} else {
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2019-07-31 16:39:07 +00:00
|
|
|
assert.Equal(t, expected, processed)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 14:39:48 +00:00
|
|
|
|
|
|
|
func TestApplyReplaceOnChangesEmptyDetailedDiff(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-07-13 14:39:48 +00:00
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
diff plugin.DiffResult
|
|
|
|
replaceOnChanges []string
|
|
|
|
hasInitErrors bool
|
|
|
|
expected plugin.DiffResult
|
|
|
|
}{
|
|
|
|
{
|
2023-06-28 16:02:04 +00:00
|
|
|
name: "Empty diff and replaceOnChanges",
|
|
|
|
diff: plugin.DiffResult{},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{},
|
|
|
|
hasInitErrors: false,
|
2023-06-28 16:02:04 +00:00
|
|
|
expected: plugin.DiffResult{},
|
2021-07-13 14:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 22:38:33 +00:00
|
|
|
name: "DiffSome and empty replaceOnChanges",
|
|
|
|
diff: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{},
|
|
|
|
hasInitErrors: false,
|
2023-01-11 22:38:33 +00:00
|
|
|
expected: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 22:38:33 +00:00
|
|
|
name: "DiffSome and non-empty replaceOnChanges",
|
|
|
|
diff: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{"a"},
|
|
|
|
hasInitErrors: false,
|
|
|
|
expected: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
ReplaceKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-28 16:02:04 +00:00
|
|
|
name: "Empty diff and replaceOnChanges w/ init errors",
|
|
|
|
diff: plugin.DiffResult{},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{},
|
|
|
|
hasInitErrors: true,
|
2023-06-28 16:02:04 +00:00
|
|
|
expected: plugin.DiffResult{},
|
2021-07-13 14:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 22:38:33 +00:00
|
|
|
name: "DiffSome and empty replaceOnChanges w/ init errors",
|
|
|
|
diff: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{},
|
|
|
|
hasInitErrors: true,
|
2023-01-11 22:38:33 +00:00
|
|
|
expected: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 22:38:33 +00:00
|
|
|
name: "DiffSome and non-empty replaceOnChanges w/ init errors",
|
|
|
|
diff: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
2021-07-13 14:39:48 +00:00
|
|
|
replaceOnChanges: []string{"a"},
|
|
|
|
hasInitErrors: true,
|
|
|
|
expected: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ChangedKeys: []resource.PropertyKey{"a"},
|
|
|
|
ReplaceKeys: []resource.PropertyKey{"a"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Empty diff and non-empty replaceOnChanges w/ init errors",
|
|
|
|
diff: plugin.DiffResult{},
|
|
|
|
replaceOnChanges: []string{"*"},
|
|
|
|
hasInitErrors: true,
|
|
|
|
expected: plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ReplaceKeys: []resource.PropertyKey{"#initerror"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2022-03-04 08:17:41 +00:00
|
|
|
c := c
|
2021-07-13 14:39:48 +00:00
|
|
|
t.Run(c.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-07-13 14:39:48 +00:00
|
|
|
newdiff, err := applyReplaceOnChanges(c.diff, c.replaceOnChanges, c.hasInitErrors)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, c.expected, newdiff)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 20:25:27 +00:00
|
|
|
|
|
|
|
func TestEngineDiff(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-11-30 20:25:27 +00:00
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
oldInputs, newInputs resource.PropertyMap
|
|
|
|
ignoreChanges []string
|
|
|
|
expected []resource.PropertyKey
|
|
|
|
expectedChanges plugin.DiffChanges
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Empty diff",
|
|
|
|
oldInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewPropertyValue(8),
|
|
|
|
"val2": resource.NewPropertyValue("hello"),
|
|
|
|
}),
|
|
|
|
newInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewPropertyValue(8),
|
|
|
|
"val2": resource.NewPropertyValue("hello"),
|
|
|
|
}),
|
|
|
|
expected: nil,
|
|
|
|
expectedChanges: plugin.DiffNone,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "All changes",
|
|
|
|
oldInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val0": resource.NewPropertyValue(3.14),
|
|
|
|
}),
|
|
|
|
newInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewNumberProperty(42),
|
|
|
|
"val2": resource.NewPropertyValue("world"),
|
|
|
|
}),
|
|
|
|
expected: []resource.PropertyKey{"val0", "val1", "val2"},
|
|
|
|
expectedChanges: plugin.DiffSome,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Some changes",
|
|
|
|
oldInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewPropertyValue(42),
|
|
|
|
}),
|
|
|
|
newInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewNumberProperty(42),
|
|
|
|
"val2": resource.NewPropertyValue("world"),
|
|
|
|
}),
|
|
|
|
expected: []resource.PropertyKey{"val2"},
|
|
|
|
expectedChanges: plugin.DiffSome,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Ignore some changes",
|
|
|
|
oldInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewPropertyValue("hello"),
|
|
|
|
}),
|
|
|
|
newInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val2": resource.NewPropertyValue(8),
|
|
|
|
}),
|
|
|
|
|
|
|
|
ignoreChanges: []string{"val1"},
|
|
|
|
expected: []resource.PropertyKey{"val2"},
|
|
|
|
expectedChanges: plugin.DiffSome,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Ignore all changes",
|
|
|
|
oldInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val1": resource.NewPropertyValue("hello"),
|
|
|
|
}),
|
|
|
|
newInputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"val2": resource.NewPropertyValue(8),
|
|
|
|
}),
|
|
|
|
|
|
|
|
ignoreChanges: []string{"val1", "val2"},
|
|
|
|
expected: nil,
|
|
|
|
expectedChanges: plugin.DiffNone,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
urn := resource.URN("urn:pulumi:dev::website-and-lambda::aws:s3/bucket:Bucket::my-bucket")
|
|
|
|
id := resource.ID("someid")
|
|
|
|
var oldOutputs resource.PropertyMap
|
|
|
|
allowUnknowns := false
|
|
|
|
provider := deploytest.Provider{}
|
|
|
|
for _, c := range cases {
|
2022-03-04 08:17:41 +00:00
|
|
|
c := c
|
2021-11-30 20:25:27 +00:00
|
|
|
t.Run(c.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-11-30 20:25:27 +00:00
|
|
|
diff, err := diffResource(urn, id, c.oldInputs, oldOutputs, c.newInputs, &provider, allowUnknowns, c.ignoreChanges)
|
|
|
|
t.Logf("diff.ChangedKeys = %v", diff.ChangedKeys)
|
|
|
|
t.Logf("diff.StableKeys = %v", diff.StableKeys)
|
|
|
|
t.Logf("diff.ReplaceKeys = %v", diff.ReplaceKeys)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, c.expectedChanges, diff.Changes)
|
|
|
|
assert.EqualValues(t, c.expected, diff.ChangedKeys)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-05-01 21:34:45 +00:00
|
|
|
|
|
|
|
func TestGenerateAliases(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const (
|
|
|
|
project = "project"
|
|
|
|
)
|
Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
stack := tokens.MustParseStackName("stack")
|
2023-05-01 21:34:45 +00:00
|
|
|
|
Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
parentTypeAlias := resource.CreateURN("myres", "test:resource:type2", "", project, stack.String())
|
|
|
|
parentNameAlias := resource.CreateURN("myres2", "test:resource:type", "", project, stack.String())
|
2023-05-01 21:34:45 +00:00
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
parentAlias *resource.URN
|
|
|
|
childAliases []resource.Alias
|
2023-09-06 12:17:02 +00:00
|
|
|
expected []resource.URN
|
2023-05-01 21:34:45 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no aliases",
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: nil,
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (type), no parent aliases",
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{Type: "test:resource:child2"},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child2::myres-child",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (name), no parent aliases",
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{Name: "child2"},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child::child2",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (type, noParent), no parent aliases",
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{
|
|
|
|
Type: "test:resource:child2",
|
|
|
|
NoParent: true,
|
|
|
|
},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:child2::myres-child",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (type, parent), no parent aliases",
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{
|
|
|
|
Type: "test:resource:child2",
|
Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
Parent: resource.CreateURN("originalparent", "test:resource:original", "", project, stack.String()),
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:original$test:resource:child2::myres-child",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (name), parent alias (type)",
|
|
|
|
parentAlias: &parentTypeAlias,
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{Name: "myres-child2"},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child::myres-child2",
|
|
|
|
"urn:pulumi:stack::project::test:resource:type2$test:resource:child::myres-child",
|
|
|
|
"urn:pulumi:stack::project::test:resource:type2$test:resource:child::myres-child2",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "child alias (name), parent alias (name)",
|
|
|
|
parentAlias: &parentNameAlias,
|
|
|
|
childAliases: []resource.Alias{
|
|
|
|
{Name: "myres-child2"},
|
|
|
|
},
|
2023-09-06 12:17:02 +00:00
|
|
|
expected: []resource.URN{
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child::myres-child2",
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child::myres2-child",
|
|
|
|
"urn:pulumi:stack::project::test:resource:type$test:resource:child::myres2-child2",
|
2023-05-01 21:34:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range cases {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
Add tokens.StackName (#14487)
<!---
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. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## 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
- [ ] 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.
-->
- [ ] 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-11-15 07:44:54 +00:00
|
|
|
parentURN := resource.CreateURN("myres", "test:resource:type", "", project, stack.String())
|
2023-05-01 21:34:45 +00:00
|
|
|
goal := &resource.Goal{
|
|
|
|
Parent: parentURN,
|
|
|
|
Name: "myres-child",
|
|
|
|
Type: "test:resource:child",
|
|
|
|
Aliases: tt.childAliases,
|
|
|
|
}
|
|
|
|
|
|
|
|
sg := newStepGenerator(&Deployment{
|
|
|
|
target: &Target{
|
|
|
|
Name: stack,
|
|
|
|
},
|
|
|
|
source: NewNullSource(project),
|
|
|
|
}, Options{}, NewUrnTargets(nil), NewUrnTargets(nil))
|
|
|
|
|
|
|
|
if tt.parentAlias != nil {
|
|
|
|
sg.aliases = map[resource.URN]resource.URN{
|
|
|
|
parentURN: *tt.parentAlias,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := sg.generateAliases(goal)
|
|
|
|
assert.Equal(t, tt.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-06-21 20:46:36 +00:00
|
|
|
|
|
|
|
func TestDeleteProtectedErrorUsesCorrectQuotesOnOS(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
err := deleteProtectedError{urn: "resource:urn"}
|
|
|
|
|
|
|
|
expectations := map[string]string{
|
|
|
|
`windows`: `"`,
|
|
|
|
`linux`: `'`,
|
|
|
|
`darwin`: `'`,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(runtime.GOOS, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
gotErrMsg := err.Error()
|
|
|
|
contains, ok := expectations[runtime.GOOS]
|
|
|
|
if !ok {
|
|
|
|
t.Skipf("no quoting expectation for %s", runtime.GOOS)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Contains(t, gotErrMsg, contains)
|
|
|
|
})
|
|
|
|
}
|
2023-12-22 21:14:04 +00:00
|
|
|
|
|
|
|
func TestStepGenerator(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("isTargetedForUpdate", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("has targeted dependencies", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
opts: Options{
|
|
|
|
TargetDependents: true,
|
|
|
|
Targets: UrnTargets{
|
|
|
|
literals: []resource.URN{"c"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
targetsActual: UrnTargets{
|
|
|
|
literals: []resource.URN{"b"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.False(t, sg.isTargetedForUpdate(&resource.State{
|
|
|
|
Dependencies: []resource.URN{"a"},
|
|
|
|
}))
|
|
|
|
assert.True(t, sg.isTargetedForUpdate(&resource.State{
|
|
|
|
Dependencies: []resource.URN{
|
|
|
|
"a",
|
|
|
|
"b", // targeted
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("checkParent", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("could not find parent resource", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
}
|
|
|
|
_, err := sg.checkParent("does-not-exist", "")
|
|
|
|
assert.ErrorContains(t, err, "could not find parent resource")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("GenerateReadSteps", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("could not find parent resource", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
}
|
|
|
|
_, err := sg.GenerateReadSteps(&readResourceEvent{
|
|
|
|
parent: "does-not-exist",
|
|
|
|
})
|
|
|
|
assert.ErrorContains(t, err, "could not find parent resource")
|
|
|
|
})
|
|
|
|
t.Run("fail generateURN", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{
|
|
|
|
"urn:pulumi:::::::": true,
|
|
|
|
},
|
|
|
|
deployment: &Deployment{
|
|
|
|
target: &Target{},
|
|
|
|
source: &nullSource{},
|
|
|
|
ctx: &plugin.Context{Diag: &deploytest.NoopSink{}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := sg.GenerateReadSteps(&readResourceEvent{})
|
|
|
|
assert.ErrorContains(t, err, "Duplicate resource URN")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("generateSteps", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("could not find parent resource", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
deployment: &Deployment{
|
|
|
|
target: &Target{},
|
|
|
|
source: &nullSource{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := sg.generateSteps(®isterResourceEvent{
|
|
|
|
goal: &resource.Goal{
|
|
|
|
Parent: "does-not-exist",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.ErrorContains(t, err, "could not find parent resource")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("determineAllowedResourcesToDeleteFromTargets", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("handle non-existent target", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
deployment: &Deployment{
|
|
|
|
prev: &Snapshot{
|
|
|
|
Resources: []*resource.State{
|
|
|
|
{
|
|
|
|
URN: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
olds: map[resource.URN]*resource.State{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
targets, err := sg.determineAllowedResourcesToDeleteFromTargets(UrnTargets{
|
|
|
|
literals: []resource.URN{"a"},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, targets)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("ScheduleDeletes", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("don't TrustDependencies", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
opts: Options{
|
|
|
|
TrustDependencies: false,
|
|
|
|
},
|
|
|
|
deployment: &Deployment{
|
|
|
|
prev: &Snapshot{},
|
|
|
|
olds: map[resource.URN]*resource.State{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
antichains := sg.ScheduleDeletes([]Step{
|
|
|
|
&DeleteStep{},
|
|
|
|
&CreateStep{},
|
|
|
|
&UpdateStep{},
|
|
|
|
})
|
|
|
|
assert.Len(t, antichains, 3)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("providerChanged", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("invalid old ProviderReference", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
deployment: &Deployment{
|
|
|
|
prev: &Snapshot{},
|
|
|
|
olds: map[resource.URN]*resource.State{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := sg.providerChanged("",
|
|
|
|
&resource.State{
|
|
|
|
Provider: "invalid-old-provider",
|
|
|
|
},
|
|
|
|
&resource.State{
|
|
|
|
Provider: "urn:pulumi:stack::project::pulumi:providers:provider::name::uuid",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.ErrorContains(t, err, "expected '::' in provider reference 'invalid-old-provider'")
|
|
|
|
})
|
|
|
|
t.Run("invalid new ProviderReference", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
deployment: &Deployment{
|
|
|
|
prev: &Snapshot{},
|
|
|
|
olds: map[resource.URN]*resource.State{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := sg.providerChanged("",
|
|
|
|
&resource.State{
|
|
|
|
Provider: "urn:pulumi:stack::project::pulumi:providers:provider::name::uuid",
|
|
|
|
},
|
|
|
|
&resource.State{
|
|
|
|
Provider: "invalid-new-provider",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.ErrorContains(t, err, "expected '::' in provider reference 'invalid-new-provider'")
|
|
|
|
})
|
|
|
|
t.Run("error getting new default provider", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
sg := &stepGenerator{
|
|
|
|
urns: map[resource.URN]bool{},
|
|
|
|
deployment: &Deployment{
|
|
|
|
prev: &Snapshot{},
|
|
|
|
olds: map[resource.URN]*resource.State{},
|
|
|
|
providers: &providers.Registry{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := sg.providerChanged("",
|
|
|
|
&resource.State{
|
|
|
|
Provider: "urn:pulumi:stack::project::pulumi:providers:provider::default_name::uuid",
|
|
|
|
},
|
|
|
|
&resource.State{
|
|
|
|
Provider: "urn:pulumi:stack::project::pulumi:providers:provider::default_new::uuid",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.ErrorContains(t, err, "failed to resolve provider reference")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|