As it stands, we serialize more than is correct when registering resources: in addition to serializing the RegisterResource RPC, we also wait for input properties to resolve in the same context. Unfortunately, this means that we can create cycles in the promise graph when a resource A is constructed in an earlier turn than some resource B and one of B's output properties is an input to resource A. These changes fix this issue by allowing input properties to resolve *before* serializing the RegisterResource RPC. Some integration tests had taken a dependency on the ordering of resources in either the output of the `pulumi` command or the checkpoint file. The only test that took a dependency on command output was updated s.t. its resources have exactly one legal topographical sort (and therefore their ordering is deterministic). The other tests were updated s.t. their validation did not depend on resource ordering.
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package examples
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/pulumi/pulumi/pkg/testing/integration"
|
|
)
|
|
|
|
func TestExamples(t *testing.T) {
|
|
cwd, err := os.Getwd()
|
|
if !assert.NoError(t, err, "expected a valid working directory: %v", err) {
|
|
return
|
|
}
|
|
|
|
var minimal integration.ProgramTestOptions
|
|
minimal = integration.ProgramTestOptions{
|
|
Dir: path.Join(cwd, "minimal"),
|
|
Dependencies: []string{"pulumi"},
|
|
Config: map[string]string{
|
|
"name": "Pulumi",
|
|
},
|
|
Secrets: map[string]string{
|
|
"secret": "this is my secret message",
|
|
},
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
// Simple runtime validation that just ensures the checkpoint was written and read.
|
|
assert.Equal(t, minimal.GetStackName(), stackInfo.Checkpoint.Stack)
|
|
},
|
|
ReportStats: integration.NewS3Reporter("us-west-2", "eng.pulumi.com", "testreports"),
|
|
}
|
|
|
|
var formattableStdout, formattableStderr bytes.Buffer
|
|
examples := []integration.ProgramTestOptions{
|
|
minimal,
|
|
{
|
|
Dir: path.Join(cwd, "dynamic-provider/simple"),
|
|
Dependencies: []string{"pulumi"},
|
|
Config: map[string]string{
|
|
"simple:config:w": "1",
|
|
"simple:config:x": "1",
|
|
"simple:config:y": "1",
|
|
},
|
|
},
|
|
{
|
|
Dir: path.Join(cwd, "dynamic-provider/multiple-turns"),
|
|
Dependencies: []string{"pulumi"},
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
for _, res := range stackInfo.Snapshot.Resources {
|
|
if res.Parent == "" {
|
|
assert.Equal(t, stackInfo.RootResource.URN, res.URN,
|
|
"every resource but the root resource should have a parent, but %v didn't", res.URN)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
Dir: path.Join(cwd, "dynamic-provider/derived-inputs"),
|
|
Dependencies: []string{"pulumi"},
|
|
},
|
|
{
|
|
Dir: path.Join(cwd, "formattable"),
|
|
Dependencies: []string{"pulumi"},
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
// Note that we're abusing this hook to validate stdout. We don't actually care about the checkpoint.
|
|
stdout := formattableStdout.String()
|
|
assert.False(t, strings.Contains(stdout, "MISSING"))
|
|
},
|
|
Stdout: &formattableStdout,
|
|
Stderr: &formattableStderr,
|
|
},
|
|
{
|
|
Dir: path.Join(cwd, "dynamic-provider/multiple-turns-2"),
|
|
Dependencies: []string{"pulumi"},
|
|
},
|
|
|
|
}
|
|
|
|
for _, ex := range examples {
|
|
example := ex
|
|
t.Run(example.Dir, func(t *testing.T) {
|
|
integration.ProgramTest(t, &example)
|
|
})
|
|
}
|
|
}
|