Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrocco committed Apr 5, 2022
1 parent bcbfa3f commit 44bfa0e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/sdk/nodejs/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,3 +1037,43 @@ func TestYAMLURL(t *testing.T) {
})
integration.ProgramTest(t, &test)
}

func TestReplaceDaemonSet(t *testing.T) {
daemonSetName := ""
test := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join("replace-daemonset", "step1"),
Quick: true,
ExpectFailure: false,
SkipRefresh: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 3, len(stackInfo.Deployment.Resources))

// Save the DaemonSet name to compare it in the step2
daemonSetName = stackInfo.Outputs["name"].(string)

// Assert that the DaemonSet was created
assert.True(t, strings.HasPrefix(stackInfo.Outputs["name"].(string), "test-replacement-"))
},
EditDirs: []integration.EditDir{
{
Dir: filepath.Join("replace-daemonset", "step2"),
Additive: true,
ExpectFailure: false,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 3, len(stackInfo.Deployment.Resources))

newDaemonSetName := stackInfo.Outputs["name"].(string)

// Assert that the DaemonSet still exists
assert.True(t, strings.HasPrefix(newDaemonSetName, "test-replacement-"))

// DaemonSet should have a different name as it was replaced
assert.True(t, daemonSetName != newDaemonSetName)
},
},
},
})
integration.ProgramTest(t, &test)
}
3 changes: 3 additions & 0 deletions tests/sdk/nodejs/replace-daemonset/step1/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: replace-daemonset
description: A program to test if the DaemonSet is replaced when the .spec.selector is updated
runtime: nodejs
17 changes: 17 additions & 0 deletions tests/sdk/nodejs/replace-daemonset/step1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as k8s from "@pulumi/kubernetes";

const appLabels = {
app: "nginx",
};

const daemonset = new k8s.apps.v1.DaemonSet("test-replacement", {
spec: {
selector: { matchLabels: appLabels },
template: {
metadata: { labels: appLabels },
spec: { containers: [{ name: "nginx", image: "nginx" }] },
},
},
});

export const name = daemonset.metadata.name;
12 changes: 12 additions & 0 deletions tests/sdk/nodejs/replace-daemonset/step1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "daemonset-replacement",
"version": "0.1.0",
"dependencies": {
"@pulumi/pulumi": "latest"
},
"devDependencies": {
},
"peerDependencies": {
"@pulumi/kubernetes": "latest"
}
}
21 changes: 21 additions & 0 deletions tests/sdk/nodejs/replace-daemonset/step1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}
18 changes: 18 additions & 0 deletions tests/sdk/nodejs/replace-daemonset/step2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as k8s from "@pulumi/kubernetes";

const appLabels = {
app: "nginx",
test: "new-value",
};

const daemonset = new k8s.apps.v1.DaemonSet("test-replacement", {
spec: {
selector: { matchLabels: appLabels },
template: {
metadata: { labels: appLabels },
spec: { containers: [{ name: "nginx", image: "nginx" }] },
},
},
});

export const name = daemonset.metadata.name;

0 comments on commit 44bfa0e

Please sign in to comment.