mirror of https://github.com/pulumi/pulumi.git
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package graph
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func NewResource(name string, deps ...resource.URN) *resource.State {
|
|
return &resource.State{
|
|
Type: tokens.Type("test"),
|
|
URN: resource.URN(name),
|
|
Inputs: make(resource.PropertyMap),
|
|
Outputs: make(resource.PropertyMap),
|
|
Dependencies: deps,
|
|
}
|
|
}
|
|
|
|
func TestBasicGraph(t *testing.T) {
|
|
a := NewResource("a")
|
|
b := NewResource("b", a.URN)
|
|
c := NewResource("c", a.URN)
|
|
d := NewResource("d", b.URN)
|
|
|
|
dg := NewDependencyGraph([]*resource.State{
|
|
a,
|
|
b,
|
|
c,
|
|
d,
|
|
})
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
b, c, d,
|
|
}, dg.DependingOn(a))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
d,
|
|
}, dg.DependingOn(b))
|
|
|
|
assert.Nil(t, dg.DependingOn(c))
|
|
assert.Nil(t, dg.DependingOn(d))
|
|
}
|
|
|
|
// Tests that we don't add the same node to the DependingOn set twice.
|
|
func TestGraphNoDuplicates(t *testing.T) {
|
|
a := NewResource("a")
|
|
b := NewResource("b", a.URN)
|
|
c := NewResource("c", a.URN)
|
|
d := NewResource("d", b.URN, c.URN)
|
|
|
|
dg := NewDependencyGraph([]*resource.State{
|
|
a,
|
|
b,
|
|
c,
|
|
d,
|
|
})
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
b, c, d,
|
|
}, dg.DependingOn(a))
|
|
}
|