pulumi/sdk/go/common/resource/urn/urn_test.go

376 lines
11 KiB
Go
Raw Permalink Normal View History

// Copyright 2016-2023, Pulumi Corporation.
2018-05-22 19:43:36 +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.
package urn_test
import (
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
"runtime"
"testing"
"github.com/stretchr/testify/assert"
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
"github.com/stretchr/testify/require"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/urn"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
)
func TestURNRoundTripping(t *testing.T) {
t.Parallel()
stack := tokens.QName("stck")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
name := "a-swell-resource"
urn := urn.New(stack, proj, parentType, typ, name)
assert.Equal(t, stack, urn.Stack())
assert.Equal(t, proj, urn.Project())
assert.Equal(t, typ, urn.QualifiedType())
assert.Equal(t, typ, urn.Type())
assert.Equal(t, name, urn.Name())
}
func TestURNRoundTripping2(t *testing.T) {
t.Parallel()
stack := tokens.QName("stck")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("parent$type")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
name := "a-swell-resource"
urn := urn.New(stack, proj, parentType, typ, name)
assert.Equal(t, stack, urn.Stack())
assert.Equal(t, proj, urn.Project())
assert.Equal(t, tokens.Type("parent$type$bang:boom/fizzle:MajorResource"), urn.QualifiedType())
assert.Equal(t, typ, urn.Type())
assert.Equal(t, name, urn.Name())
}
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
func TestURNRoundTripping3(t *testing.T) {
t.Parallel()
stack := tokens.QName("stck")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("parent$type")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
name := "a-swell-resource::with_awkward$names"
urn := urn.New(stack, proj, parentType, typ, name)
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
assert.Equal(t, stack, urn.Stack())
assert.Equal(t, proj, urn.Project())
assert.Equal(t, tokens.Type("parent$type$bang:boom/fizzle:MajorResource"), urn.QualifiedType())
assert.Equal(t, typ, urn.Type())
assert.Equal(t, name, urn.Name())
}
func TestIsValid(t *testing.T) {
t.Parallel()
goodUrns := []string{
"urn:pulumi:test::test::pulumi:pulumi:Stack::test-test",
"urn:pulumi:stack-name::project-name::my:customtype$aws:s3/bucket:Bucket::bob",
"urn:pulumi:stack::project::type::",
"urn:pulumi:stack::project::type::some really ::^&\n*():: crazy name",
Don't validate URNs (#14741) <!--- 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. --> Fix an issue with users with spaces in project names. They aren't technically `token.Name`s so this method was failing them, but they've happened to work up till now. ## 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-12-08 09:38:32 +00:00
"urn:pulumi:stack::project with whitespace::type::some name",
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
}
for _, str := range goodUrns {
urn := urn.URN(str)
Allow anything in resource names (#14107) <!--- 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 https://github.com/pulumi/pulumi/issues/13968. Fixes https://github.com/pulumi/pulumi/issues/8949. This requires changing the parsing of URN's slightly, it is _very_ likely that providers will need to update to handle URNs like this correctly. This changes resource names to be `string` not `QName`. We never validated this before and it turns out that users have put all manner of text for resource names so we just updating the system to correctly reflect that. ## 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-11-20 08:59:00 +00:00
assert.True(t, urn.IsValid(), "IsValid expected to be true: %v", urn)
}
}
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
func TestComponentAccess(t *testing.T) {
t.Parallel()
type ComponentTestCase struct {
urn string
expected string
}
t.Run("Stack component", func(t *testing.T) {
t.Parallel()
cases := []ComponentTestCase{
{urn: "urn:pulumi:stack::test::pulumi:pulumi:Stack::test-test", expected: "stack"},
{urn: "urn:pulumi:stack::::::", expected: "stack"},
{urn: "urn:pulumi:::test::pulumi:pulumi:Stack::test-test", expected: ""},
{urn: "urn:pulumi:::::::", expected: ""},
}
for _, test := range cases {
urn, err := urn.Parse(test.urn)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.Equal(t, test.urn, string(urn))
assert.Equalf(t, tokens.QName(test.expected), urn.Stack(),
"Expecting stack to be '%v' from urn '%v'", test.expected, test.urn)
}
})
t.Run("Project component", func(t *testing.T) {
t.Parallel()
cases := []ComponentTestCase{
{urn: "urn:pulumi:stack::proj::pulumi:pulumi:Stack::test-test", expected: "proj"},
{urn: "urn:pulumi:::proj::::", expected: "proj"},
{urn: "urn:pulumi:stack::::pulumi:pulumi:Stack::test-test", expected: ""},
{urn: "urn:pulumi:::::::", expected: ""},
}
for _, test := range cases {
urn, err := urn.Parse(test.urn)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.Equal(t, test.urn, string(urn))
assert.Equalf(t, tokens.PackageName(test.expected), urn.Project(),
"Expecting project to be '%v' from urn '%v'", test.expected, test.urn)
}
})
t.Run("QualifiedType component", func(t *testing.T) {
t.Parallel()
cases := []ComponentTestCase{
{urn: "urn:pulumi:stack::proj::qualified$type::test-test", expected: "qualified$type"},
{urn: "urn:pulumi:::::qualified$type::", expected: "qualified$type"},
{urn: "urn:pulumi:stack::proj::::test-test", expected: ""},
{urn: "urn:pulumi:::::::", expected: ""},
}
for _, test := range cases {
urn, err := urn.Parse(test.urn)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.Equal(t, test.urn, string(urn))
assert.Equalf(t, tokens.Type(test.expected), urn.QualifiedType(),
"Expecting qualified type to be '%v' from urn '%v'", test.expected, test.urn)
}
})
t.Run("Type component", func(t *testing.T) {
t.Parallel()
cases := []ComponentTestCase{
{urn: "urn:pulumi:stack::proj::very$qualified$type::test-test", expected: "type"},
{urn: "urn:pulumi:::::very$qualified$type::", expected: "type"},
{urn: "urn:pulumi:stack::proj::qualified$type::test-test", expected: "type"},
{urn: "urn:pulumi:::::qualified$type::", expected: "type"},
{urn: "urn:pulumi:stack::proj::qualified-type::test-test", expected: "qualified-type"},
{urn: "urn:pulumi:::::qualified-type::", expected: "qualified-type"},
{urn: "urn:pulumi:stack::proj::::test-test", expected: ""},
{urn: "urn:pulumi:::::::", expected: ""},
}
for _, test := range cases {
urn, err := urn.Parse(test.urn)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.Equal(t, test.urn, string(urn))
assert.Equalf(t, tokens.Type(test.expected), urn.Type(),
"Expecting type to be '%v' from urn '%v'", test.expected, test.urn)
}
})
t.Run("Name component", func(t *testing.T) {
t.Parallel()
cases := []ComponentTestCase{
{urn: "urn:pulumi:stack::proj::qualified$type::name", expected: "name"},
{urn: "urn:pulumi:::::::name", expected: "name"},
{urn: "urn:pulumi:stack::proj::qualified$type::", expected: ""},
{urn: "urn:pulumi:::::::", expected: ""},
{
urn: "urn:pulumi::stack::proj::type::a-longer-name",
expected: "a-longer-name",
},
{
urn: "urn:pulumi::stack::proj::type::a name with spaces",
expected: "a name with spaces",
},
{
urn: "urn:pulumi::stack::proj::type::a-name-with::a-name-separator",
expected: "a-name-with::a-name-separator",
},
{
urn: "urn:pulumi::stack::proj::type::a-name-with::many::name::separators",
expected: "a-name-with::many::name::separators",
},
}
for _, test := range cases {
urn, err := urn.Parse(test.urn)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.Equal(t, test.urn, string(urn))
assert.Equalf(t, test.expected, urn.Name(),
"Expecting name to be '%v' from urn '%v'", test.expected, test.urn)
}
})
}
func TestURNParse(t *testing.T) {
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
t.Parallel()
t.Run("Positive Tests", func(t *testing.T) {
t.Parallel()
goodUrns := []string{
"urn:pulumi:test::test::pulumi:pulumi:Stack::test-test",
"urn:pulumi:stack-name::project-name::my:customtype$aws:s3/bucket:Bucket::bob",
"urn:pulumi:stack::project::type::",
"urn:pulumi:stack::project::type::some really ::^&\n*():: crazy name",
"urn:pulumi:stack::project with whitespace::type::some name",
}
for _, str := range goodUrns {
urn, err := urn.Parse(str)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.NoErrorf(t, err, "Expecting %v to parse as a good urn", str)
assert.Equal(t, str, string(urn), "A parsed URN should be the same as the string that it was parsed from")
}
})
t.Run("Negative Tests", func(t *testing.T) {
t.Parallel()
t.Run("Empty String", func(t *testing.T) {
t.Parallel()
urn, err := urn.Parse("")
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.ErrorContains(t, err, "missing required URN")
assert.Empty(t, urn)
})
t.Run("Invalid URNs", func(t *testing.T) {
t.Parallel()
invalidUrns := []string{
"URN:PULUMI:TEST::TEST::PULUMI:PULUMI:STACK::TEST-TEST",
"urn:not-pulumi:stack-name::project-name::my:customtype$aws:s3/bucket:Bucket::bob",
"The quick brown fox",
"urn:pulumi:stack::too-few-elements",
}
for _, str := range invalidUrns {
urn, err := urn.Parse(str)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.ErrorContainsf(t, err, "invalid URN", "Expecting %v to parse as an invalid urn")
assert.Empty(t, urn)
}
})
})
}
func TestParseOptionalURN(t *testing.T) {
t.Parallel()
t.Run("Positive Tests", func(t *testing.T) {
t.Parallel()
goodUrns := []string{
"urn:pulumi:test::test::pulumi:pulumi:Stack::test-test",
"urn:pulumi:stack-name::project-name::my:customtype$aws:s3/bucket:Bucket::bob",
"urn:pulumi:stack::project::type::",
"urn:pulumi:stack::project::type::some really ::^&\n*():: crazy name",
"urn:pulumi:stack::project with whitespace::type::some name",
"",
}
for _, str := range goodUrns {
urn, err := urn.ParseOptional(str)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.NoErrorf(t, err, "Expecting '%v' to parse as a good urn", str)
assert.Equal(t, str, string(urn))
}
})
t.Run("Invalid URNs", func(t *testing.T) {
t.Parallel()
invalidUrns := []string{
"URN:PULUMI:TEST::TEST::PULUMI:PULUMI:STACK::TEST-TEST",
"urn:not-pulumi:stack-name::project-name::my:customtype$aws:s3/bucket:Bucket::bob",
"The quick brown fox",
"urn:pulumi:stack::too-few-elements",
}
for _, str := range invalidUrns {
urn, err := urn.ParseOptional(str)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.ErrorContainsf(t, err, "invalid URN", "Expecting %v to parse as an invalid urn")
assert.Empty(t, urn)
}
})
}
func TestQuote(t *testing.T) {
t.Parallel()
urn, err := urn.Parse("urn:pulumi:test::test::pulumi:pulumi:Stack::test-test")
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
require.NoError(t, err)
require.NotEmpty(t, urn)
expected := "'urn:pulumi:test::test::pulumi:pulumi:Stack::test-test'"
if runtime.GOOS == "windows" {
expected = "\"urn:pulumi:test::test::pulumi:pulumi:Stack::test-test\""
}
assert.Equal(t, expected, urn.Quote())
}
func TestRename(t *testing.T) {
t.Parallel()
stack := tokens.QName("stack")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("parent$type")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
name := "a-swell-resource"
oldURN := urn.New(stack, proj, parentType, typ, name)
renamed := oldURN.Rename("a-better-resource")
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.NotEqual(t, oldURN, renamed)
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
assert.Equal(t,
urn.New(stack, proj, parentType, typ, "a-better-resource"),
Stop using strings.Split in urn.go (#15669) # Description `strings.Split` is being used to extract delimited components of the urn, this is inefficient when only one component is being accessed. This changes to scan the urn string to find the required component, this is measurably more efficient. <!--- 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. --> <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> ## 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. --> --------- Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-03-14 04:47:23 +00:00
renamed)
}
func TestRenameStack(t *testing.T) {
t.Parallel()
stack := tokens.QName("stack")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("parent$type")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
name := "a-swell-resource"
oldURN := urn.New(stack, proj, parentType, typ, name)
renamed := oldURN.RenameStack(tokens.MustParseStackName("a-better-stack"))
assert.NotEqual(t, oldURN, renamed)
assert.Equal(t,
urn.New("a-better-stack", proj, parentType, typ, name),
renamed)
}
func TestRenameProject(t *testing.T) {
t.Parallel()
stack := tokens.QName("stack")
proj := tokens.PackageName("foo/bar/baz")
parentType := tokens.Type("parent$type")
typ := tokens.Type("bang:boom/fizzle:MajorResource")
name := "a-swell-resource"
oldURN := urn.New(stack, proj, parentType, typ, name)
renamed := oldURN.RenameProject(tokens.PackageName("a-better-project"))
assert.NotEqual(t, oldURN, renamed)
assert.Equal(t,
urn.New(stack, "a-better-project", parentType, typ, name),
renamed)
}