Skip to content

Commit

Permalink
Deserialize Assets with their Sig (#16073)
Browse files Browse the repository at this point in the history
<!--- 
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

Deserialize Assets with their Sig field set. This is necessary to round
trip them. This matches the behavior of Archives.

Fixes pulumi/pulumi-go-provider#234

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
  • Loading branch information
iwahbe committed Apr 26, 2024
1 parent 52b58ae commit 88b0dd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: pkg
description: deserialze assets with their sig
2 changes: 1 addition & 1 deletion sdk/go/common/resource/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func Deserialize(obj map[string]interface{}) (*Asset, bool, error) {
uri = u
}

return &Asset{Hash: hash, Text: text, Path: path, URI: uri}, true, nil
return &Asset{Sig: AssetSig, Hash: hash, Text: text, Path: path, URI: uri}, true, nil
}

// HasContents indicates whether or not an asset's contents can be read.
Expand Down
4 changes: 4 additions & 0 deletions sdk/go/common/resource/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestAssetSerialize(t *testing.T) {
assert.True(t, assetDes.IsText())
assert.Equal(t, text, assetDes.Text)
assert.Equal(t, "e34c74529110661faae4e121e57165ff4cb4dbdde1ef9770098aa3695e6b6704", assetDes.Hash)
assert.Equal(t, AssetSig, assetDes.Sig)

// another text asset with the same contents, should hash the same way.
text2 := "a test asset"
Expand Down Expand Up @@ -135,6 +136,7 @@ func TestAssetSerialize(t *testing.T) {
assert.True(t, assetDes.IsPath())
assert.Equal(t, file, assetDes.Path)
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", assetDes.Hash)
assert.Equal(t, AssetSig, assetDes.Sig)

arch, err := rarchive.FromAssets(map[string]interface{}{"foo": asset})
assert.NoError(t, err)
Expand Down Expand Up @@ -176,6 +178,7 @@ func TestAssetSerialize(t *testing.T) {
assert.True(t, assetDes.IsURI())
assert.Equal(t, url, assetDes.URI)
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", assetDes.Hash)
assert.Equal(t, AssetSig, assetDes.Sig)

arch, err := rarchive.FromAssets(map[string]interface{}{"foo": asset})
assert.NoError(t, err)
Expand Down Expand Up @@ -215,6 +218,7 @@ func TestAssetSerialize(t *testing.T) {
assert.True(t, isasset)
assert.True(t, emptyDes.IsText())
assert.Equal(t, "", emptyDes.Text)
assert.Equal(t, AssetSig, emptyDes.Sig)

// Check that a text asset with it's text removed shows as "no content".
asset, err := rasset.FromText("a very different and special test asset")
Expand Down

0 comments on commit 88b0dd1

Please sign in to comment.