2017-07-17 19:38:57 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
2017-07-17 19:38:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAssetSerialize(t *testing.T) {
|
|
|
|
// Ensure that asset and archive serialization round trips.
|
|
|
|
text := "a test asset"
|
|
|
|
asset := resource.NewTextAsset(text)
|
2017-09-15 01:40:44 +02:00
|
|
|
assetProps, err := MarshalPropertyValue(resource.NewAssetProperty(asset), MarshalOptions{})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assetValue, err := UnmarshalPropertyValue(assetProps, MarshalOptions{})
|
|
|
|
assert.Nil(t, err)
|
2017-07-17 19:38:57 +02:00
|
|
|
assert.True(t, assetValue.IsAsset())
|
|
|
|
assetDes := assetValue.AssetValue()
|
|
|
|
assert.True(t, assetDes.IsText())
|
|
|
|
assert.Equal(t, text, assetDes.Text)
|
|
|
|
|
|
|
|
arch := resource.NewAssetArchive(map[string]resource.Asset{"foo": asset})
|
2017-09-15 01:40:44 +02:00
|
|
|
archProps, err := MarshalPropertyValue(resource.NewArchiveProperty(arch), MarshalOptions{})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
archValue, err := UnmarshalPropertyValue(archProps, MarshalOptions{})
|
|
|
|
assert.Nil(t, err)
|
2017-07-17 19:38:57 +02:00
|
|
|
assert.True(t, archValue.IsArchive())
|
|
|
|
archDes := archValue.ArchiveValue()
|
|
|
|
assert.True(t, archDes.IsAssets())
|
|
|
|
assert.Equal(t, 1, len(archDes.Assets))
|
|
|
|
assert.True(t, archDes.Assets["foo"].IsText())
|
|
|
|
assert.Equal(t, text, archDes.Assets["foo"].Text)
|
|
|
|
}
|
2017-07-31 20:38:31 +02:00
|
|
|
|
|
|
|
func TestComputedSerialize(t *testing.T) {
|
|
|
|
// Ensure that computed properties survive round trips.
|
2017-09-15 01:40:44 +02:00
|
|
|
opts := MarshalOptions{AllowUnknowns: true}
|
2017-07-31 20:38:31 +02:00
|
|
|
{
|
2017-09-15 01:40:44 +02:00
|
|
|
cprop, err := MarshalPropertyValue(
|
2017-07-31 20:38:31 +02:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewStringProperty("")}), opts)
|
2017-09-15 01:40:44 +02:00
|
|
|
assert.Nil(t, err)
|
|
|
|
cpropU, err := UnmarshalPropertyValue(cprop, opts)
|
|
|
|
assert.Nil(t, err)
|
2017-07-31 20:38:31 +02:00
|
|
|
assert.True(t, cpropU.IsComputed())
|
|
|
|
assert.True(t, cpropU.ComputedValue().Element.IsString())
|
|
|
|
}
|
|
|
|
{
|
2017-09-15 01:40:44 +02:00
|
|
|
cprop, err := MarshalPropertyValue(
|
2017-07-31 20:38:31 +02:00
|
|
|
resource.NewComputedProperty(
|
|
|
|
resource.Computed{Element: resource.NewNumberProperty(0)}), opts)
|
2017-09-15 01:40:44 +02:00
|
|
|
assert.Nil(t, err)
|
|
|
|
cpropU, err := UnmarshalPropertyValue(cprop, opts)
|
|
|
|
assert.Nil(t, err)
|
2017-07-31 20:38:31 +02:00
|
|
|
assert.True(t, cpropU.IsComputed())
|
|
|
|
assert.True(t, cpropU.ComputedValue().Element.IsNumber())
|
|
|
|
}
|
|
|
|
}
|