2021-09-13 16:05:31 +00:00
|
|
|
// Copyright 2016-2021, 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.
|
2017-07-17 17:38:57 +00:00
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2017-10-22 20:39:21 +00:00
|
|
|
"fmt"
|
2018-10-31 02:59:36 +00:00
|
|
|
"runtime"
|
2017-07-17 17:38:57 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-01-17 09:35:20 +00:00
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2017-07-17 17:38:57 +00:00
|
|
|
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/archive"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
2017-07-17 17:38:57 +00:00
|
|
|
)
|
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
func setProperty(key resource.PropertyKey, s *structpb.Value, k string, v interface{}) {
|
|
|
|
marshaled, err := MarshalPropertyValue(key, resource.NewPropertyValue(v), MarshalOptions{})
|
2023-02-15 01:06:56 +00:00
|
|
|
contract.Assertf(err == nil, "error marshaling property value")
|
2019-08-06 23:32:05 +00:00
|
|
|
s.GetStructValue().Fields[k] = marshaled
|
|
|
|
}
|
|
|
|
|
2017-07-17 17:38:57 +00:00
|
|
|
func TestAssetSerialize(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-17 17:38:57 +00:00
|
|
|
// Ensure that asset and archive serialization round trips.
|
|
|
|
text := "a test asset"
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("a test asset uri")
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
anAsset, err := asset.FromText(text)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
assert.Equal(t, text, anAsset.Text)
|
|
|
|
assert.Equal(t, "e34c74529110661faae4e121e57165ff4cb4dbdde1ef9770098aa3695e6b6704", anAsset.Hash)
|
|
|
|
assetProps, err := MarshalPropertyValue(pk, resource.NewAssetProperty(anAsset), MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-01-12 19:27:33 +00:00
|
|
|
t.Logf("%v", assetProps)
|
2021-09-10 20:18:08 +00:00
|
|
|
assetValue, err := UnmarshalPropertyValue("", assetProps, MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-07-17 17:38:57 +00:00
|
|
|
assert.True(t, assetValue.IsAsset())
|
|
|
|
assetDes := assetValue.AssetValue()
|
|
|
|
assert.True(t, assetDes.IsText())
|
|
|
|
assert.Equal(t, text, assetDes.Text)
|
2017-10-22 20:39:21 +00:00
|
|
|
assert.Equal(t, "e34c74529110661faae4e121e57165ff4cb4dbdde1ef9770098aa3695e6b6704", assetDes.Hash)
|
2017-07-17 17:38:57 +00:00
|
|
|
|
2019-08-06 23:32:05 +00:00
|
|
|
// Ensure that an invalid asset produces an error.
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetHashProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", assetProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected asset hash of type float64")
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetHashProperty, anAsset.Hash)
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetTextProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", assetProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected asset text of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetTextProperty, "")
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetPathProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", assetProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected asset path of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetPathProperty, "")
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetURIProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", assetProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected asset URI of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, assetProps, resource.AssetURIProperty, "")
|
2019-08-06 23:32:05 +00:00
|
|
|
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
arch, err := archive.FromAssets(map[string]interface{}{"foo": anAsset})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-31 02:59:36 +00:00
|
|
|
switch runtime.Version() {
|
|
|
|
case "go1.9":
|
|
|
|
assert.Equal(t, "d8ce0142b3b10300c7c76487fad770f794c1e84e1b0c73a4b2e1503d4fbac093", arch.Hash)
|
|
|
|
default:
|
|
|
|
// Go 1.10 introduced breaking changes to archive/zip and archive/tar headers
|
|
|
|
assert.Equal(t, "27ab4a14a617df10cff3e1cf4e30cf510302afe56bf4cc91f84041c9f7b62fd8", arch.Hash)
|
|
|
|
}
|
2021-09-10 20:18:08 +00:00
|
|
|
archProps, err := MarshalPropertyValue(pk, resource.NewArchiveProperty(arch), MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
archValue, err := UnmarshalPropertyValue("", archProps, MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-07-17 17:38:57 +00:00
|
|
|
assert.True(t, archValue.IsArchive())
|
|
|
|
archDes := archValue.ArchiveValue()
|
|
|
|
assert.True(t, archDes.IsAssets())
|
|
|
|
assert.Equal(t, 1, len(archDes.Assets))
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
assert.True(t, archDes.Assets["foo"].(*asset.Asset).IsText())
|
|
|
|
assert.Equal(t, text, archDes.Assets["foo"].(*asset.Asset).Text)
|
2018-10-31 02:59:36 +00:00
|
|
|
switch runtime.Version() {
|
|
|
|
case "go1.9":
|
|
|
|
assert.Equal(t, "d8ce0142b3b10300c7c76487fad770f794c1e84e1b0c73a4b2e1503d4fbac093", archDes.Hash)
|
|
|
|
default:
|
|
|
|
// Go 1.10 introduced breaking changes to archive/zip and archive/tar headers
|
|
|
|
assert.Equal(t, "27ab4a14a617df10cff3e1cf4e30cf510302afe56bf4cc91f84041c9f7b62fd8", archDes.Hash)
|
|
|
|
}
|
2019-08-06 23:32:05 +00:00
|
|
|
|
|
|
|
// Ensure that an invalid archive produces an error.
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveHashProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", archProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected archive hash of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveHashProperty, arch.Hash)
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveAssetsProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", archProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected archive contents of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveAssetsProperty, nil)
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchivePathProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", archProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected archive path of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchivePathProperty, "")
|
2019-08-06 23:32:05 +00:00
|
|
|
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveURIProperty, 0)
|
|
|
|
_, err = UnmarshalPropertyValue("", archProps, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected archive URI of type float64")
|
2021-09-10 20:18:08 +00:00
|
|
|
setProperty(pk, archProps, resource.ArchiveURIProperty, "")
|
2017-07-17 17:38:57 +00:00
|
|
|
}
|
2017-07-31 18:38:31 +00:00
|
|
|
|
|
|
|
func TestComputedSerialize(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-31 18:38:31 +00:00
|
|
|
// Ensure that computed properties survive round trips.
|
2017-11-03 20:40:15 +00:00
|
|
|
opts := MarshalOptions{KeepUnknowns: true}
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
2017-07-31 18:38:31 +00:00
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2017-07-31 18:38:31 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
cpropU, err := UnmarshalPropertyValue(pk, cprop, opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-07-31 18:38:31 +00:00
|
|
|
assert.True(t, cpropU.IsComputed())
|
2018-02-05 22:44:23 +00:00
|
|
|
assert.True(t, cpropU.Input().Element.IsString())
|
2017-07-31 18:38:31 +00:00
|
|
|
}
|
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2017-07-31 18:38:31 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewNumberProperty(0)}), opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
cpropU, err := UnmarshalPropertyValue(pk, cprop, opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-07-31 18:38:31 +00:00
|
|
|
assert.True(t, cpropU.IsComputed())
|
2018-02-05 22:44:23 +00:00
|
|
|
assert.True(t, cpropU.Input().Element.IsNumber())
|
2017-07-31 18:38:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-03 20:40:15 +00:00
|
|
|
|
|
|
|
func TestComputedSkip(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-11-03 20:40:15 +00:00
|
|
|
// Ensure that computed properties are skipped when KeepUnknowns == false.
|
|
|
|
opts := MarshalOptions{KeepUnknowns: false}
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
2017-11-03 20:40:15 +00:00
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2017-11-03 20:40:15 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-11-03 20:40:15 +00:00
|
|
|
assert.Nil(t, cprop)
|
|
|
|
}
|
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2017-11-03 20:40:15 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewNumberProperty(0)}), opts)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-11-03 20:40:15 +00:00
|
|
|
assert.Nil(t, cprop)
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 20:21:47 +00:00
|
|
|
|
|
|
|
func TestComputedReject(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-01-09 20:21:47 +00:00
|
|
|
// Ensure that computed properties produce errors when RejectUnknowns == true.
|
|
|
|
opts := MarshalOptions{RejectUnknowns: true}
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
2018-01-09 20:21:47 +00:00
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2018-01-09 20:21:47 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected unknown property value for \"pk\"")
|
2018-01-09 20:21:47 +00:00
|
|
|
assert.Nil(t, cprop)
|
|
|
|
}
|
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
cprop, err := MarshalPropertyValue(pk,
|
2018-01-09 20:21:47 +00:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), MarshalOptions{KeepUnknowns: true})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
cpropU, err := UnmarshalPropertyValue(pk, cprop, opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected unknown property value for \"pk\"")
|
2018-01-09 20:21:47 +00:00
|
|
|
assert.Nil(t, cpropU)
|
|
|
|
}
|
|
|
|
}
|
2019-01-29 01:38:16 +00:00
|
|
|
|
2019-08-24 19:27:39 +00:00
|
|
|
func TestAssetReject(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-08-24 19:27:39 +00:00
|
|
|
// Ensure that asset and archive properties produce errors when RejectAssets == true.
|
|
|
|
|
|
|
|
opts := MarshalOptions{RejectAssets: true}
|
|
|
|
|
|
|
|
text := "a test asset"
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("an asset URI")
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
asset, err := asset.FromText(text)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2019-08-24 19:27:39 +00:00
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
assetProps, err := MarshalPropertyValue(pk, resource.NewAssetProperty(asset), opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected Asset property value for \"an asset URI\"")
|
2019-08-24 19:27:39 +00:00
|
|
|
assert.Nil(t, assetProps)
|
|
|
|
}
|
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
assetProps, err := MarshalPropertyValue(pk, resource.NewAssetProperty(asset), MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
assetPropU, err := UnmarshalPropertyValue(pk, assetProps, opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected Asset property value for \"an asset URI\"")
|
2019-08-24 19:27:39 +00:00
|
|
|
assert.Nil(t, assetPropU)
|
|
|
|
}
|
|
|
|
|
Move assets and archives to their own package (#15157)
<!---
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
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
arch, err := archive.FromAssets(map[string]interface{}{"foo": asset})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2019-08-24 19:27:39 +00:00
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
archProps, err := MarshalPropertyValue(pk, resource.NewArchiveProperty(arch), opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected Asset Archive property value for \"an asset URI\"")
|
2019-08-24 19:27:39 +00:00
|
|
|
assert.Nil(t, archProps)
|
|
|
|
}
|
|
|
|
{
|
2021-09-10 20:18:08 +00:00
|
|
|
archProps, err := MarshalPropertyValue(pk, resource.NewArchiveProperty(arch), MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
archValue, err := UnmarshalPropertyValue(pk, archProps, opts)
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unexpected Asset property value for \"foo\"")
|
2019-08-24 19:27:39 +00:00
|
|
|
assert.Nil(t, archValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 01:38:16 +00:00
|
|
|
func TestUnsupportedSecret(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-29 01:38:16 +00:00
|
|
|
rawProp := resource.NewObjectProperty(resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
resource.SigKey: resource.SecretSig,
|
2020-02-26 01:45:36 +00:00
|
|
|
"value": "foo",
|
2019-01-29 01:38:16 +00:00
|
|
|
}))
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
|
|
|
prop, err := MarshalPropertyValue(pk, rawProp, MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
val, err := UnmarshalPropertyValue(pk, prop, MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2020-02-26 01:45:36 +00:00
|
|
|
assert.True(t, val.IsString())
|
|
|
|
assert.False(t, val.IsSecret())
|
|
|
|
assert.Equal(t, "foo", val.StringValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSupportedSecret(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-02-26 01:45:36 +00:00
|
|
|
rawProp := resource.NewObjectProperty(resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
resource.SigKey: resource.SecretSig,
|
|
|
|
"value": "foo",
|
|
|
|
}))
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
|
|
|
|
|
|
|
prop, err := MarshalPropertyValue(pk, rawProp, MarshalOptions{KeepSecrets: true})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
val, err := UnmarshalPropertyValue(pk, prop, MarshalOptions{KeepSecrets: true})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2020-02-26 01:45:36 +00:00
|
|
|
assert.False(t, val.IsString())
|
|
|
|
assert.True(t, val.IsSecret())
|
|
|
|
assert.Equal(t, "foo", val.SecretValue().Element.StringValue())
|
2019-01-29 01:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnknownSig(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-29 01:38:16 +00:00
|
|
|
rawProp := resource.NewObjectProperty(resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
resource.SigKey: "foobar",
|
|
|
|
}))
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
|
|
|
|
|
|
|
prop, err := MarshalPropertyValue(pk, rawProp, MarshalOptions{})
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
_, err = UnmarshalPropertyValue(pk, prop, MarshalOptions{})
|
2023-12-08 06:40:14 +00:00
|
|
|
assert.EqualError(t, err, "unrecognized signature 'foobar' in property map for \"pk\"")
|
2019-01-29 01:38:16 +00:00
|
|
|
}
|
2020-03-18 18:39:13 +00:00
|
|
|
|
|
|
|
func TestSkipInternalKeys(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-03-18 18:39:13 +00:00
|
|
|
opts := MarshalOptions{SkipInternalKeys: true}
|
|
|
|
expected := &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"keepers": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
props := resource.NewPropertyMapFromMap(map[string]interface{}{
|
|
|
|
"__defaults": []string{},
|
|
|
|
"keepers": map[string]interface{}{
|
|
|
|
"__defaults": []string{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
actual, err := MarshalProperties(props, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
2020-10-27 17:12:12 +00:00
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
func TestMarshalProperties(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
opts MarshalOptions
|
|
|
|
props resource.PropertyMap
|
|
|
|
expected *structpb.Struct
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.MakeOutput(resource.NewStringProperty("")),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty(""),
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: "hello",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known with deps (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: "hello",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: "hello",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: "hello",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (default)",
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.MakeOutput(resource.NewStringProperty("")),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty(""),
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known with deps (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (KeepOutputValues)",
|
2021-09-27 16:01:40 +00:00
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
2021-09-13 16:05:31 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"foo": resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"foo": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt
|
2021-09-13 16:05:31 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
actual, err := MarshalProperties(tt.props, tt.opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:12:12 +00:00
|
|
|
func TestResourceReference(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-10-27 17:12:12 +00:00
|
|
|
// Test round-trip
|
|
|
|
opts := MarshalOptions{KeepResources: true}
|
2021-01-21 23:40:27 +00:00
|
|
|
rawProp := resource.MakeCustomResourceReference("fakeURN", "fakeID", "fakeVersion")
|
2021-09-10 20:18:08 +00:00
|
|
|
pk := resource.PropertyKey("pk")
|
|
|
|
prop, err := MarshalPropertyValue(pk, rawProp, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 20:18:08 +00:00
|
|
|
actual, err := UnmarshalPropertyValue(pk, prop, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, rawProp, *actual)
|
|
|
|
|
|
|
|
// Test unmarshaling as an ID
|
|
|
|
opts.KeepResources = false
|
2021-09-10 20:18:08 +00:00
|
|
|
actual, err = UnmarshalPropertyValue(pk, prop, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
2021-01-21 23:40:27 +00:00
|
|
|
assert.Equal(t, resource.NewStringProperty(rawProp.ResourceReferenceValue().ID.StringValue()), *actual)
|
2020-10-27 17:12:12 +00:00
|
|
|
|
|
|
|
// Test marshaling as an ID
|
2021-09-10 20:18:08 +00:00
|
|
|
prop, err = MarshalPropertyValue(pk, rawProp, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
opts.KeepResources = true
|
2021-09-10 20:18:08 +00:00
|
|
|
actual, err = UnmarshalPropertyValue(pk, prop, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
2021-01-21 23:40:27 +00:00
|
|
|
assert.Equal(t, resource.NewStringProperty(rawProp.ResourceReferenceValue().ID.StringValue()), *actual)
|
2020-10-27 17:12:12 +00:00
|
|
|
|
|
|
|
// Test unmarshaling as a URN
|
2021-01-21 23:40:27 +00:00
|
|
|
rawProp = resource.MakeComponentResourceReference("fakeURN", "fakeVersion")
|
2021-09-10 20:18:08 +00:00
|
|
|
prop, err = MarshalPropertyValue(pk, rawProp, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
opts.KeepResources = false
|
2021-09-10 20:18:08 +00:00
|
|
|
actual, err = UnmarshalPropertyValue(pk, prop, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resource.NewStringProperty(string(rawProp.ResourceReferenceValue().URN)), *actual)
|
|
|
|
|
|
|
|
// Test marshaling as a URN
|
2021-09-10 20:18:08 +00:00
|
|
|
prop, err = MarshalPropertyValue(pk, rawProp, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
opts.KeepResources = true
|
2021-09-10 20:18:08 +00:00
|
|
|
actual, err = UnmarshalPropertyValue(pk, prop, opts)
|
2020-10-27 17:12:12 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resource.NewStringProperty(string(rawProp.ResourceReferenceValue().URN)), *actual)
|
|
|
|
}
|
2021-06-07 20:30:52 +00:00
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
func TestOutputValueRoundTrip(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
raw resource.PropertyValue
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "unknown",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known with deps",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("secret"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("secret"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt
|
2021-09-13 16:05:31 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
opts := MarshalOptions{KeepOutputValues: true}
|
|
|
|
prop, err := MarshalPropertyValue("", tt.raw, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
actual, err := UnmarshalPropertyValue("", prop, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.raw, *actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputValueMarshaling(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
opts MarshalOptions
|
|
|
|
raw resource.PropertyValue
|
|
|
|
expected *structpb.Value
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{}),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown (default)",
|
|
|
|
raw: resource.MakeOutput(resource.NewStringProperty("")),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known with deps (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Known: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (default)",
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{}),
|
|
|
|
expected: &structpb.Value{
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
2021-09-13 16:05:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.MakeOutput(resource.NewStringProperty("")),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("hello"),
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepSecrets: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.SecretSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepSecrets: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Known: true,
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.SecretSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (KeepUnknowns, KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true, KeepSecrets: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.SecretSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (KeepUnknowns, KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true, KeepSecrets: true},
|
|
|
|
raw: resource.NewOutputProperty(resource.Output{
|
|
|
|
Element: resource.NewStringProperty("shhh"),
|
|
|
|
Secret: true,
|
|
|
|
Dependencies: []resource.URN{"fakeURN1", "fakeURN2"},
|
|
|
|
}),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.SecretSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown value (KeepOutputValues)",
|
|
|
|
opts: MarshalOptions{KeepOutputValues: true},
|
|
|
|
raw: resource.MakeOutput(resource.NewStringProperty("")),
|
|
|
|
expected: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt
|
2021-09-13 16:05:31 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
actual, err := MarshalPropertyValue("", tt.raw, tt.opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputValueUnmarshaling(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
ptr := func(v resource.PropertyValue) *resource.PropertyValue {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
opts MarshalOptions
|
|
|
|
raw *structpb.Value
|
|
|
|
expected *resource.PropertyValue
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "unknown (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("hello")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "known with deps (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "hello"},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("hello")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("shhh")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("shhh")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (default)",
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeComputed(resource.NewStringProperty(""))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeComputed(resource.NewStringProperty(""))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeComputed(resource.NewStringProperty(""))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeComputed(resource.NewStringProperty(""))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("shhh")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.NewStringProperty("shhh")),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret (KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepSecrets: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeSecret(resource.NewStringProperty("shhh"))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "secret with deps (KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepSecrets: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: "shhh"},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeSecret(resource.NewStringProperty("shhh"))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret (KeepUnknowns, KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true, KeepSecrets: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeSecret(resource.MakeComputed(resource.NewStringProperty("")))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown secret with deps (KeepUnknowns, KeepSecrets)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true, KeepSecrets: true},
|
|
|
|
raw: &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
"secret": {
|
|
|
|
Kind: &structpb.Value_BoolValue{BoolValue: true},
|
|
|
|
},
|
|
|
|
"dependencies": {
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{
|
|
|
|
Values: []*structpb.Value{
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN1"}},
|
|
|
|
{Kind: &structpb.Value_StringValue{StringValue: "fakeURN2"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: ptr(resource.MakeSecret(resource.MakeComputed(resource.NewStringProperty("")))),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt
|
2021-09-13 16:05:31 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-09-13 16:05:31 +00:00
|
|
|
prop, err := UnmarshalPropertyValue("", tt.raw, tt.opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.expected, prop)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:30:52 +00:00
|
|
|
func TestMarshalPropertiesDiscardsListNestedUnknowns(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-06-07 20:30:52 +00:00
|
|
|
proto := pbStruct("resources", pbList(pbString(UnknownStringValue)))
|
|
|
|
|
|
|
|
propsWithUnknowns, err := UnmarshalProperties(proto, MarshalOptions{KeepUnknowns: true})
|
|
|
|
if err != nil {
|
2021-11-03 18:25:20 +00:00
|
|
|
t.Errorf("UnmarshalProperties failed: %v", err)
|
2021-06-07 20:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protobufStruct, err := MarshalProperties(propsWithUnknowns, MarshalOptions{KeepUnknowns: false})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
protobufValue := &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: protobufStruct,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assertValidProtobufValue(t, protobufValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func pbString(s string) *structpb.Value {
|
|
|
|
return &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: s,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pbStruct(name string, value *structpb.Value) *structpb.Struct {
|
|
|
|
return &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
name: value,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pbList(elems ...*structpb.Value) *structpb.Value {
|
|
|
|
return &structpb.Value{
|
|
|
|
Kind: &structpb.Value_ListValue{
|
|
|
|
ListValue: &structpb.ListValue{Values: elems},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertValidProtobufValue(t *testing.T, value *structpb.Value) {
|
|
|
|
err := walkValueSelfWithDescendants(value, "", func(path string, v *structpb.Value) error {
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-03 18:25:20 +00:00
|
|
|
t.Errorf("This is not a valid *structpb.Value: %v\n%v", value, err)
|
2021-06-07 20:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func walkValueSelfWithDescendants(
|
|
|
|
v *structpb.Value,
|
|
|
|
path string,
|
2023-03-03 16:36:39 +00:00
|
|
|
visit func(path string, v *structpb.Value) error,
|
|
|
|
) error {
|
2021-06-07 20:30:52 +00:00
|
|
|
if v == nil {
|
2022-10-09 14:58:33 +00:00
|
|
|
return fmt.Errorf("bad *structpb.Value nil at %s", path)
|
2021-06-07 20:30:52 +00:00
|
|
|
}
|
|
|
|
err := visit(path, v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch v.Kind.(type) {
|
|
|
|
case *structpb.Value_ListValue:
|
|
|
|
values := v.GetListValue().GetValues()
|
|
|
|
for i, v := range values {
|
|
|
|
err = walkValueSelfWithDescendants(v, fmt.Sprintf("%s[%d]", path, i), visit)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *structpb.Value_StructValue:
|
|
|
|
s := v.GetStructValue()
|
|
|
|
for fn, fv := range s.Fields {
|
|
|
|
err = walkValueSelfWithDescendants(fv, fmt.Sprintf(`%s["%s"]`, path, fn), visit)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *structpb.Value_NumberValue:
|
|
|
|
return nil
|
|
|
|
case *structpb.Value_StringValue:
|
|
|
|
return nil
|
|
|
|
case *structpb.Value_BoolValue:
|
|
|
|
return nil
|
|
|
|
case *structpb.Value_NullValue:
|
|
|
|
return nil
|
|
|
|
default:
|
2022-10-09 14:58:33 +00:00
|
|
|
return fmt.Errorf("bad *structpb.Value of unknown type at %s: %v", path, v)
|
2021-06-07 20:30:52 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
|
|
|
|
func TestMarshalPropertiesDontSkipOutputs(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
opts MarshalOptions
|
|
|
|
props resource.PropertyMap
|
|
|
|
expected *structpb.Struct
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Computed (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"message": resource.MakeComputed(resource.NewStringProperty("")),
|
|
|
|
"nested": resource.NewObjectProperty(resource.PropertyMap{
|
|
|
|
"value": resource.MakeComputed(resource.NewStringProperty("")),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"message": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
"nested": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Output (KeepUnknowns)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true},
|
|
|
|
props: resource.PropertyMap{
|
|
|
|
"message": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
"nested": resource.NewObjectProperty(resource.PropertyMap{
|
|
|
|
"value": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"message": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
"nested": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-27 16:01:40 +00:00
|
|
|
name: "Output (KeepUnknowns, KeepOutputValues)",
|
|
|
|
opts: MarshalOptions{KeepUnknowns: true, KeepOutputValues: true},
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
props: resource.PropertyMap{
|
|
|
|
"message": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
"nested": resource.NewObjectProperty(resource.PropertyMap{
|
|
|
|
"value": resource.NewOutputProperty(resource.Output{}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
expected: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"message": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.OutputValueSig},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nested": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
"value": {
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{
|
|
|
|
StringValue: resource.OutputValueSig,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
Enable output values by default (#8014)
* Enable output values by default
Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.
* Marshal unknown as unknown string when `!KeepOutputValues`
Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.
Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.
* Add MarshalOptions.DontSkipOutputs and use where needed
Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:
```go
if v.IsOutput() {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:
```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).
I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:
```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```
`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.
* [sdk/nodejs] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
* [sdk/python] Deserialize output values
This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 15:57:04 +00:00
|
|
|
actual, err := MarshalProperties(tt.props, tt.opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-02-02 11:09:58 +00:00
|
|
|
|
|
|
|
func TestUpgradeToOutputValues(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
opts := MarshalOptions{
|
2024-02-06 08:22:46 +00:00
|
|
|
KeepUnknowns: true, KeepSecrets: true, KeepOutputValues: true, KeepResources: true,
|
2024-02-02 11:09:58 +00:00
|
|
|
}
|
|
|
|
upgradeOpts := MarshalOptions{
|
2024-02-06 08:22:46 +00:00
|
|
|
KeepUnknowns: true, KeepSecrets: true, KeepOutputValues: true, KeepResources: true, UpgradeToOutputValues: true,
|
2024-02-02 11:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pk := resource.PropertyKey("pk")
|
|
|
|
// Unknown
|
|
|
|
{
|
|
|
|
prop, err := MarshalPropertyValue(pk,
|
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsOutput())
|
|
|
|
assert.False(t, propU.OutputValue().Known)
|
|
|
|
assert.False(t, propU.OutputValue().Secret)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
prop, err := MarshalPropertyValue(pk,
|
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsOutput())
|
|
|
|
assert.False(t, propU.OutputValue().Known)
|
|
|
|
assert.False(t, propU.OutputValue().Secret)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Secrets
|
|
|
|
{
|
|
|
|
elem := resource.NewStringProperty("hello")
|
|
|
|
prop, err := MarshalPropertyValue(pk,
|
|
|
|
resource.NewSecretProperty(
|
|
|
|
&resource.Secret{Element: elem}), upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsOutput())
|
|
|
|
assert.True(t, propU.OutputValue().Known)
|
|
|
|
assert.True(t, propU.OutputValue().Secret)
|
|
|
|
assert.Equal(t, elem, propU.OutputValue().Element)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
elem := resource.NewStringProperty("hello")
|
|
|
|
prop, err := MarshalPropertyValue(pk,
|
|
|
|
resource.NewSecretProperty(
|
|
|
|
&resource.Secret{Element: elem}), opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsOutput())
|
|
|
|
assert.True(t, propU.OutputValue().Known)
|
|
|
|
assert.True(t, propU.OutputValue().Secret)
|
|
|
|
assert.Equal(t, elem, propU.OutputValue().Element)
|
|
|
|
}
|
2024-02-06 08:22:46 +00:00
|
|
|
|
|
|
|
// Resource reference
|
|
|
|
{
|
|
|
|
elem := resource.ResourceReference{
|
|
|
|
URN: resource.CreateURN("name", "type", "", "project", "stack"),
|
|
|
|
ID: resource.MakeComputed(resource.NewStringProperty("")),
|
|
|
|
}
|
|
|
|
prop, err := MarshalPropertyValue(pk, resource.NewResourceReferenceProperty(elem), upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsResourceReference())
|
|
|
|
assert.Equal(t, elem.URN, propU.ResourceReferenceValue().URN)
|
|
|
|
id := propU.ResourceReferenceValue().ID
|
|
|
|
// ResourceReferences are always Computed even if output upgrades are turned on.
|
|
|
|
assert.True(t, id.IsComputed())
|
|
|
|
}
|
|
|
|
{
|
|
|
|
elem := resource.ResourceReference{
|
|
|
|
URN: resource.CreateURN("name", "type", "", "project", "stack"),
|
|
|
|
ID: resource.MakeComputed(resource.NewStringProperty("")),
|
|
|
|
}
|
|
|
|
prop, err := MarshalPropertyValue(pk, resource.NewResourceReferenceProperty(elem), opts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsResourceReference())
|
|
|
|
assert.Equal(t, elem.URN, propU.ResourceReferenceValue().URN)
|
|
|
|
id := propU.ResourceReferenceValue().ID
|
|
|
|
assert.True(t, id.IsComputed())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some SDKs send the unknown string value instead of "" for the unknown ID
|
|
|
|
{
|
|
|
|
urn := string(resource.CreateURN("name", "type", "", "project", "stack"))
|
|
|
|
prop := &structpb.Value{
|
|
|
|
Kind: &structpb.Value_StructValue{
|
|
|
|
StructValue: &structpb.Struct{
|
|
|
|
Fields: map[string]*structpb.Value{
|
|
|
|
resource.SigKey: {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: resource.ResourceReferenceSig},
|
|
|
|
},
|
|
|
|
"urn": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: urn},
|
|
|
|
},
|
|
|
|
"id": {
|
|
|
|
Kind: &structpb.Value_StringValue{StringValue: UnknownStringValue},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
propU, err := UnmarshalPropertyValue(pk, prop, upgradeOpts)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, propU.IsResourceReference())
|
|
|
|
assert.Equal(t, resource.URN(urn), propU.ResourceReferenceValue().URN)
|
|
|
|
id := propU.ResourceReferenceValue().ID
|
|
|
|
assert.True(t, id.IsComputed())
|
|
|
|
}
|
2024-02-02 11:09:58 +00:00
|
|
|
}
|