pulumi/examples/examples_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

106 lines
3 KiB
Go

// Copyright 2016-2018, 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/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.NotNil(t, stackInfo.Deployment)
},
}
var formattableStdout, formattableStderr bytes.Buffer
examples := []integration.ProgramTestOptions{
minimal,
{
Dir: path.Join(cwd, "dynamic-provider/simple"),
Dependencies: []string{"@pulumi/pulumi"},
Config: map[string]string{
"simple:config:w": "1",
"simple:config:x": "1",
"simple:config:y": "1",
},
Verbose: true,
DebugUpdates: true,
DebugLogLevel: 12,
},
{
Dir: path.Join(cwd, "dynamic-provider/multiple-turns"),
Dependencies: []string{"@pulumi/pulumi"},
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
for _, res := range stackInfo.Deployment.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/pulumi"},
},
{
Dir: path.Join(cwd, "formattable"),
Dependencies: []string{"@pulumi/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/pulumi"},
},
{
Dir: path.Join(cwd, "compat/v0.10.0/minimal"),
Dependencies: []string{"@pulumi/pulumi"},
Config: map[string]string{
"name": "Pulumi",
},
Secrets: map[string]string{
"secret": "this is my secret message",
},
},
}
for _, example := range examples {
ex := example.With(integration.ProgramTestOptions{
ReportStats: integration.NewS3Reporter("us-west-2", "eng.pulumi.com", "testreports"),
})
t.Run(example.Dir, func(t *testing.T) {
integration.ProgramTest(t, &ex)
})
}
}