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"
|
|
|
|
|
|
|
|
"github.com/pulumi/lumi/pkg/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAssetSerialize(t *testing.T) {
|
|
|
|
// Ensure that asset and archive serialization round trips.
|
|
|
|
text := "a test asset"
|
|
|
|
asset := resource.NewTextAsset(text)
|
2017-07-20 18:06:39 +02:00
|
|
|
assetProps := MarshalPropertyValue(resource.NewAssetProperty(asset), MarshalOptions{})
|
2017-07-17 19:38:57 +02:00
|
|
|
assetValue := UnmarshalPropertyValue(assetProps, MarshalOptions{})
|
|
|
|
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-07-20 18:06:39 +02:00
|
|
|
archProps := MarshalPropertyValue(resource.NewArchiveProperty(arch), MarshalOptions{})
|
2017-07-17 19:38:57 +02:00
|
|
|
archValue := UnmarshalPropertyValue(archProps, MarshalOptions{})
|
|
|
|
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)
|
|
|
|
}
|