2017-12-07 18:44:38 +01:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
|
|
|
package ints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2018-02-28 19:02:02 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/apitype"
|
2017-12-07 18:44:38 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
|
|
"github.com/pulumi/pulumi/pkg/testing/integration"
|
|
|
|
)
|
|
|
|
|
2018-02-28 19:02:02 +01:00
|
|
|
func validateResources(t *testing.T, resources []apitype.Resource, expectedNames ...string) {
|
2018-02-06 01:29:20 +01:00
|
|
|
// 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.
|
2018-02-12 22:13:13 +01:00
|
|
|
assert.Equal(t, len(resources), len(expectedNames)+1)
|
2018-02-06 01:29:20 +01:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 18:44:38 +01:00
|
|
|
// TestSteps tests many combinations of creates, updates, deletes, replacements, and so on.
|
|
|
|
func TestSteps(t *testing.T) {
|
2017-12-09 01:59:28 +01:00
|
|
|
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
2017-12-07 18:44:38 +01:00
|
|
|
Dir: "step1",
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2017-12-07 18:44:38 +01:00
|
|
|
Quick: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources, "a", "b", "c", "d")
|
2017-12-07 18:44:38 +01:00
|
|
|
},
|
|
|
|
EditDirs: []integration.EditDir{
|
|
|
|
{
|
2018-01-10 01:47:17 +01:00
|
|
|
Dir: "step2",
|
|
|
|
Additive: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources, "a", "b", "c", "e")
|
2017-12-07 18:44:38 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-01-10 01:47:17 +01:00
|
|
|
Dir: "step3",
|
|
|
|
Additive: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources, "a", "c", "e")
|
2017-12-07 18:44:38 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-01-10 01:47:17 +01:00
|
|
|
Dir: "step4",
|
|
|
|
Additive: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources, "a", "c", "e")
|
2017-12-11 18:22:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-01-10 01:47:17 +01:00
|
|
|
Dir: "step5",
|
|
|
|
Additive: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources, "a", "c", "e")
|
2017-12-07 18:44:38 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-01-10 01:47:17 +01:00
|
|
|
Dir: "step6",
|
|
|
|
Additive: true,
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
|
|
assert.NotNil(t, stackInfo.Checkpoint.Latest)
|
2018-02-06 01:29:20 +01:00
|
|
|
validateResources(t, stackInfo.Checkpoint.Latest.Resources)
|
2017-12-07 18:44:38 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|