* Make `async:true` the default for `invoke` calls (#3750) * Switch away from native grpc impl. (#3728) * Remove usage of the 'deasync' library from @pulumi/pulumi. (#3752) * Only retry as long as we get unavailable back. Anything else continues. (#3769) * Handle all errors for now. (#3781) * Do not assume --yes was present when using pulumi in non-interactive mode (#3793) * Upgrade all paths for sdk and pkg to v2 * Backport C# invoke classes and other recent gen changes (#4288) Adjust C# generation * Replace IDeployment with a sealed class (#4318) Replace IDeployment with a sealed class * .NET: default to args subtype rather than Args.Empty (#4320) * Adding system namespace for Dotnet code gen This is required for using Obsolute attributes for deprecations ``` Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'ObsoleteAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj] Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'Obsolete' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj] ``` * Fix the nullability of config type properties in C# codegen (#4379)
175 lines
3.8 KiB
Go
175 lines
3.8 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package graph
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/resource/deploy/providers"
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/tokens"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func NewProviderResource(pkg, name, id string, deps ...resource.URN) *resource.State {
|
|
t := providers.MakeProviderType(tokens.Package(pkg))
|
|
return &resource.State{
|
|
Type: t,
|
|
URN: resource.NewURN("test", "test", "", t, tokens.QName(name)),
|
|
ID: resource.ID(id),
|
|
Inputs: resource.PropertyMap{},
|
|
Outputs: resource.PropertyMap{},
|
|
Dependencies: deps,
|
|
}
|
|
}
|
|
|
|
func NewResource(name string, provider *resource.State, deps ...resource.URN) *resource.State {
|
|
prov := ""
|
|
if provider != nil {
|
|
p, err := providers.NewReference(provider.URN, provider.ID)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
prov = p.String()
|
|
}
|
|
|
|
t := tokens.Type("test:test:test")
|
|
return &resource.State{
|
|
Type: t,
|
|
URN: resource.NewURN("test", "test", "", t, tokens.QName(name)),
|
|
Inputs: resource.PropertyMap{},
|
|
Outputs: resource.PropertyMap{},
|
|
Dependencies: deps,
|
|
Provider: prov,
|
|
}
|
|
}
|
|
|
|
func TestBasicGraph(t *testing.T) {
|
|
pA := NewProviderResource("test", "pA", "0")
|
|
a := NewResource("a", pA)
|
|
b := NewResource("b", pA, a.URN)
|
|
pB := NewProviderResource("test", "pB", "1", a.URN, b.URN)
|
|
c := NewResource("c", pB, a.URN)
|
|
d := NewResource("d", nil, b.URN)
|
|
|
|
dg := NewDependencyGraph([]*resource.State{
|
|
pA,
|
|
a,
|
|
b,
|
|
pB,
|
|
c,
|
|
d,
|
|
})
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
a, b, pB, c, d,
|
|
}, dg.DependingOn(pA, nil))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
b, pB, c, d,
|
|
}, dg.DependingOn(a, nil))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
pB, c, d,
|
|
}, dg.DependingOn(b, nil))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
c,
|
|
}, dg.DependingOn(pB, nil))
|
|
|
|
assert.Nil(t, dg.DependingOn(c, nil))
|
|
assert.Nil(t, dg.DependingOn(d, nil))
|
|
|
|
assert.Nil(t, dg.DependingOn(pA, map[resource.URN]bool{
|
|
a.URN: true,
|
|
b.URN: true,
|
|
}))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
a, pB, c,
|
|
}, dg.DependingOn(pA, map[resource.URN]bool{
|
|
b.URN: true,
|
|
}))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
b, pB, c, d,
|
|
}, dg.DependingOn(pA, map[resource.URN]bool{
|
|
a.URN: true,
|
|
}))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
c,
|
|
}, dg.DependingOn(a, map[resource.URN]bool{
|
|
b.URN: true,
|
|
pB.URN: true,
|
|
}))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
pB, c,
|
|
}, dg.DependingOn(a, map[resource.URN]bool{
|
|
b.URN: true,
|
|
}))
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
d,
|
|
}, dg.DependingOn(b, map[resource.URN]bool{
|
|
pB.URN: true,
|
|
}))
|
|
}
|
|
|
|
// Tests that we don't add the same node to the DependingOn set twice.
|
|
func TestGraphNoDuplicates(t *testing.T) {
|
|
a := NewResource("a", nil)
|
|
b := NewResource("b", nil, a.URN)
|
|
c := NewResource("c", nil, a.URN)
|
|
d := NewResource("d", nil, b.URN, c.URN)
|
|
|
|
dg := NewDependencyGraph([]*resource.State{
|
|
a,
|
|
b,
|
|
c,
|
|
d,
|
|
})
|
|
|
|
assert.Equal(t, []*resource.State{
|
|
b, c, d,
|
|
}, dg.DependingOn(a, nil))
|
|
}
|
|
|
|
func TestDependenciesOf(t *testing.T) {
|
|
pA := NewProviderResource("test", "pA", "0")
|
|
a := NewResource("a", pA)
|
|
b := NewResource("b", pA, a.URN)
|
|
c := NewResource("c", pA)
|
|
d := NewResource("d", pA)
|
|
d.Parent = a.URN
|
|
|
|
dg := NewDependencyGraph([]*resource.State{
|
|
pA,
|
|
a,
|
|
b,
|
|
c,
|
|
d,
|
|
})
|
|
|
|
aDepends := dg.DependenciesOf(a)
|
|
assert.True(t, aDepends[pA])
|
|
assert.False(t, aDepends[a])
|
|
assert.False(t, aDepends[b])
|
|
|
|
bDepends := dg.DependenciesOf(b)
|
|
assert.True(t, bDepends[pA])
|
|
assert.True(t, bDepends[a])
|
|
assert.False(t, bDepends[b])
|
|
|
|
cDepends := dg.DependenciesOf(c)
|
|
assert.True(t, cDepends[pA])
|
|
assert.False(t, cDepends[a])
|
|
assert.False(t, cDepends[b])
|
|
|
|
dDepends := dg.DependenciesOf(d)
|
|
assert.True(t, dDepends[pA])
|
|
assert.True(t, dDepends[a]) // due to A being the parent of D
|
|
assert.False(t, dDepends[b])
|
|
assert.False(t, dDepends[c])
|
|
}
|