pulumi/pkg/resource/deploy/plan_test.go
Pat Gavlin bc08574136
Add an API for importing stack outputs (#2180)
These changes add a new resource to the Pulumi SDK,
`pulumi.StackReference`, that represents a reference to another stack.
This resource has an output property, `outputs`, that contains the
complete set of outputs for the referenced stack. The Pulumi account
performing the deployment that creates a `StackReference`  must have
access to the referenced stack or the call will fail.

This resource is implemented by a builtin provider managed by the engine.
This provider will be used for any custom resources and invokes inside
the `pulumi:pulumi` module. Currently this provider supports only the
`pulumi:pulumi:StackReference` resource.

Fixes #109.
2018-11-14 13:33:35 -08:00

58 lines
1.4 KiB
Go

package deploy
import (
"testing"
"time"
"github.com/pulumi/pulumi/pkg/resource"
"github.com/pulumi/pulumi/pkg/resource/plugin"
"github.com/pulumi/pulumi/pkg/tokens"
"github.com/pulumi/pulumi/pkg/version"
"github.com/stretchr/testify/assert"
)
func newResource(name string) *resource.State {
ty := tokens.Type("test")
return &resource.State{
Type: ty,
URN: resource.NewURN(tokens.QName("teststack"), tokens.PackageName("pkg"), ty, ty, tokens.QName(name)),
Inputs: make(resource.PropertyMap),
Outputs: make(resource.PropertyMap),
}
}
func newSnapshot(resources []*resource.State, ops []resource.Operation) *Snapshot {
return NewSnapshot(Manifest{
Time: time.Now(),
Version: version.Version,
Plugins: nil,
}, resources, ops)
}
func TestPendingOperationsPlan(t *testing.T) {
resourceA := newResource("a")
resourceB := newResource("b")
snap := newSnapshot([]*resource.State{
resourceA,
}, []resource.Operation{
{
Type: resource.OperationTypeCreating,
Resource: resourceB,
},
})
_, err := NewPlan(&plugin.Context{}, &Target{}, snap, &fixedSource{}, nil, false, nil)
if !assert.Error(t, err) {
t.FailNow()
}
invalidErr, ok := err.(PlanPendingOperationsError)
if !assert.True(t, ok) {
t.FailNow()
}
assert.Len(t, invalidErr.Operations, 1)
assert.Equal(t, resourceB.URN, invalidErr.Operations[0].Resource.URN)
assert.Equal(t, resource.OperationTypeCreating, invalidErr.Operations[0].Type)
}