pulumi/tests/integration/transformations/transformations_test.go
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* 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)
2020-04-14 09:30:25 +01:00

197 lines
7.2 KiB
Go

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
package ints
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/v2/testing/integration"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/tokens"
)
var dirs = []string{
"simple",
}
func TestNodejsTransformations(t *testing.T) {
for _, dir := range dirs {
d := filepath.Join("nodejs", dir)
t.Run(d, func(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: d,
Dependencies: []string{"@pulumi/pulumi"},
Quick: true,
ExtraRuntimeValidation: validator("nodejs"),
})
})
}
}
func TestPythonTransformations(t *testing.T) {
for _, dir := range dirs {
d := filepath.Join("python", dir)
t.Run(d, func(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: d,
Dependencies: []string{
filepath.Join("..", "..", "..", "sdk", "python", "env", "src"),
},
Quick: true,
ExtraRuntimeValidation: validator("python"),
})
})
}
}
func validator(language string) func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
dynamicResName := "pulumi-" + language + ":dynamic:Resource"
return func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
foundRes1 := false
foundRes2Child := false
foundRes3 := false
foundRes4Child := false
foundRes5Child := false
for _, res := range stack.Deployment.Resources {
// "res1" has a transformation which adds additionalSecretOutputs
if res.URN.Name() == "res1" {
foundRes1 = true
assert.Equal(t, res.Type, tokens.Type(dynamicResName))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("output"))
}
// "res2" has a transformation which adds additionalSecretOutputs to it's
// "child"
if res.URN.Name() == "res2-child" {
foundRes2Child = true
assert.Equal(t, res.Type, tokens.Type(dynamicResName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("output"))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("output2"))
}
// "res3" is impacted by a global stack transformation which sets
// optionalDefault to "stackDefault"
if res.URN.Name() == "res3" {
foundRes3 = true
assert.Equal(t, res.Type, tokens.Type(dynamicResName))
optionalInput := res.Inputs["optionalInput"]
assert.NotNil(t, optionalInput)
assert.Equal(t, "stackDefault", optionalInput.(string))
}
// "res4" is impacted by two component parent transformations which set
// optionalDefault to "default1" and then "default2" and also a global stack
// transformation which sets optionalDefault to "stackDefault". The end
// result should be "stackDefault".
if res.URN.Name() == "res4-child" {
foundRes4Child = true
assert.Equal(t, res.Type, tokens.Type(dynamicResName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
optionalInput := res.Inputs["optionalInput"]
assert.NotNil(t, optionalInput)
assert.Equal(t, "stackDefault", optionalInput.(string))
}
// "res5" modifies one of its children to depend on another of its children.
if res.URN.Name() == "res5-child1" {
foundRes5Child = true
assert.Equal(t, res.Type, tokens.Type(dynamicResName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
// TODO[pulumi/pulumi#3282] Due to this bug, the dependency information
// will not be correctly recorded in the state file, and so cannot be
// verified here.
//
// assert.Len(t, res.PropertyDependencies, 1)
input := res.Inputs["input"]
assert.NotNil(t, input)
assert.Equal(t, "b", input.(string))
}
}
assert.True(t, foundRes1)
assert.True(t, foundRes2Child)
assert.True(t, foundRes3)
assert.True(t, foundRes4Child)
assert.True(t, foundRes5Child)
}
}
func TestDotNetTransformations(t *testing.T) {
for _, dir := range dirs {
d := filepath.Join("dotnet", dir)
t.Run(d, func(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: d,
Dependencies: []string{"Pulumi"},
Quick: true,
ExtraRuntimeValidation: dotNetValidator(),
})
})
}
}
// .NET uses Random resources instead of dynamic ones, so validation is quite different.
func dotNetValidator() func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
resName := "random:index/randomString:RandomString"
return func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
foundRes1 := false
foundRes2Child := false
foundRes3 := false
foundRes4Child := false
foundRes5Child := false
for _, res := range stack.Deployment.Resources {
// "res1" has a transformation which adds additionalSecretOutputs
if res.URN.Name() == "res1" {
foundRes1 = true
assert.Equal(t, res.Type, tokens.Type(resName))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("length"))
}
// "res2" has a transformation which adds additionalSecretOutputs to it's
// "child" and sets minUpper to 2
if res.URN.Name() == "res2-child" {
foundRes2Child = true
assert.Equal(t, res.Type, tokens.Type(resName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("length"))
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("special"))
minUpper := res.Inputs["minUpper"]
assert.NotNil(t, minUpper)
assert.Equal(t, 2.0, minUpper.(float64))
}
// "res3" is impacted by a global stack transformation which sets
// overrideSpecial to "stackvalue"
if res.URN.Name() == "res3" {
foundRes3 = true
assert.Equal(t, res.Type, tokens.Type(resName))
overrideSpecial := res.Inputs["overrideSpecial"]
assert.NotNil(t, overrideSpecial)
assert.Equal(t, "stackvalue", overrideSpecial.(string))
}
// "res4" is impacted by two component parent transformations which appends
// to overrideSpecial "value1" and then "value2" and also a global stack
// transformation which appends "stackvalue" to overrideSpecial. The end
// result should be "value1value2stackvalue".
if res.URN.Name() == "res4-child" {
foundRes4Child = true
assert.Equal(t, res.Type, tokens.Type(resName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
overrideSpecial := res.Inputs["overrideSpecial"]
assert.NotNil(t, overrideSpecial)
assert.Equal(t, "value1value2stackvalue", overrideSpecial.(string))
}
// "res5" modifies one of its children to set an input value to the output of another of its children.
if res.URN.Name() == "res5-child1" {
foundRes5Child = true
assert.Equal(t, res.Type, tokens.Type(resName))
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
length := res.Inputs["length"]
assert.NotNil(t, length)
assert.Equal(t, 6.0, length.(float64))
}
}
assert.True(t, foundRes1)
assert.True(t, foundRes2Child)
assert.True(t, foundRes3)
assert.True(t, foundRes4Child)
assert.True(t, foundRes5Child)
}
}