pulumi/tests/integration/steps/steps_test.go
Luke Hoban 5ede33e03d
Run tests against managed stacks backend instead of FnF (#1092)
Tests now target managed stacks instead of local stacks.

The existing logged in user and target backend API are used unless PULUMI_ACCES_TOKEN is defined, in which case tests are run under that access token and against the PULUMI_API backend.

For developer machines, we will now need to be logged in to Pulumi to run tests, and whichever default API backend is logged in (the one listed as current in ~/.pulumi/credentials.json) will be used. If you need to override these, provide PULUMI_ACCESS_TOKEN and possibly PULUMI_API.

For Travis, we currently target the staging service using the Pulumi Bot user.

We have decided to run tests in the pulumi organization. This can be overridden for local testing (or in Travis in the future) by defining PULUMI_API_OWNER_ORGANIZATION and using an access token with access to that organization.

Part of pulumi/home#195.
2018-04-02 21:34:54 -07:00

92 lines
2.9 KiB
Go

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
package ints
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/apitype"
"github.com/pulumi/pulumi/pkg/resource"
"github.com/pulumi/pulumi/pkg/testing/integration"
)
func validateResources(t *testing.T, resources []apitype.Resource, expectedNames ...string) {
// Build the lookup table of expected resource names.
expectedNamesTable := make(map[string]struct{})
for _, n := range expectedNames {
expectedNamesTable[n] = struct{}{}
}
// Ensure that the resource count is correct.
assert.Equal(t, len(resources), len(expectedNames)+1)
// Pull out the stack resource, which must be the first resource in the checkpoint.
stackRes := resources[0]
assert.Equal(t, resource.RootStackType, stackRes.URN.Type())
// Ensure that exactly the provided resources are in the array.
for _, res := range resources[1:] {
name := string(res.URN.Name())
_, ok := expectedNamesTable[name]
assert.True(t, ok)
delete(expectedNamesTable, name)
}
}
// TestSteps tests many combinations of creates, updates, deletes, replacements, and so on.
func TestSteps(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: "step1",
Dependencies: []string{"@pulumi/pulumi"},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources, "a", "b", "c", "d")
},
EditDirs: []integration.EditDir{
{
Dir: "step2",
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources, "a", "b", "c", "e")
},
},
{
Dir: "step3",
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
},
},
{
Dir: "step4",
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
},
},
{
Dir: "step5",
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
},
},
{
Dir: "step6",
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
validateResources(t, stackInfo.Deployment.Resources)
},
},
},
})
}