Skip to content

Commit

Permalink
Add integration test for transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelprazak committed Jun 9, 2022
1 parent 14b4156 commit edeb480
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 4 deletions.
88 changes: 84 additions & 4 deletions tests/integration/java_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package integration

import (
"fmt"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"os"
"path/filepath"
"testing"
Expand All @@ -19,10 +20,11 @@ func TestIntegrations(t *testing.T) {
t.Run("stack-reference", func(t *testing.T) {
dir := filepath.Join(getCwd(t), "stack-reference")
test := getJavaBase(t, integration.ProgramTestOptions{
Dir: dir,
Quick: true,
DebugUpdates: false,
DebugLogLevel: 0,
Dir: dir,
Quick: true,
DestroyOnCleanup: true,
DebugUpdates: false,
DebugLogLevel: 0,
Env: []string{
"PULUMI_EXCESSIVE_DEBUG_OUTPUT=false",
},
Expand Down Expand Up @@ -63,6 +65,18 @@ func TestIntegrations(t *testing.T) {
})
integration.ProgramTest(t, &test)
})
t.Run("stack-transformation", func(t *testing.T) {
dir := filepath.Join(getCwd(t), "stack-transformation")
test := getJavaBase(t, integration.ProgramTestOptions{
Dir: dir,
Quick: true,
DestroyOnCleanup: true,
DebugUpdates: false,
DebugLogLevel: 0,
ExtraRuntimeValidation: stackTransformationValidator(),
})
integration.ProgramTest(t, &test)
})
}

func getJavaBase(t *testing.T, testSpecificOptions integration.ProgramTestOptions) integration.ProgramTestOptions {
Expand Down Expand Up @@ -103,3 +117,69 @@ func getJavaBase(t *testing.T, testSpecificOptions integration.ProgramTestOption
t.Logf("Running test with opts.CloudURL: %s", opts.CloudURL)
return opts
}

func stackTransformationValidator() 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)
}
}
2 changes: 2 additions & 0 deletions tests/integration/stack-transformation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.mvn/wrapper/maven-wrapper.jar
/target/
3 changes: 3 additions & 0 deletions tests/integration/stack-transformation/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: stack-transformation
runtime: java
description: A minimal Java Pulumi program with Maven builds
109 changes: 109 additions & 0 deletions tests/integration/stack-transformation/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pulumi.example</groupId>
<artifactId>stacktransformation</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<mainClass>${project.groupId}.${project.artifactId}.App</mainClass>
<mainArgs/>
<pulumiSdkVersion>0.0.1</pulumiSdkVersion>
<pulumiRandomVersion>4.6.0</pulumiRandomVersion>
</properties>

<profiles>
<profile>
<id>env-dependencies</id>
<activation>
<property>
<name>env.PULUMI_JAVA_SDK_VERSION</name>
</property>
</activation>
<properties>
<pulumiSdkVersion>${env.PULUMI_JAVA_SDK_VERSION}</pulumiSdkVersion>
<pulumiRandomVersion>${env.PULUMI_RANDOM_PROVIDER_SDK_VERSION}</pulumiRandomVersion>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>${pulumiSdkVersion}</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>random</artifactId>
<version>${pulumiRandomVersion}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>${mainArgs}</commandlineArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-wrapper-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mavenVersion>3.8.5</mavenVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit edeb480

Please sign in to comment.