2017-07-23 20:12:17 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
|
|
|
package examples
|
|
|
|
|
|
|
|
import (
|
2017-11-14 20:26:41 +01:00
|
|
|
"bytes"
|
2017-07-23 20:12:17 +02:00
|
|
|
"os"
|
|
|
|
"path"
|
2017-11-14 20:26:41 +01:00
|
|
|
"strings"
|
2017-07-23 20:12:17 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2017-10-28 05:03:38 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource/stack"
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/testing/integration"
|
2017-07-23 20:12:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExamples(t *testing.T) {
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if !assert.NoError(t, err, "expected a valid working directory: %v", err) {
|
|
|
|
return
|
|
|
|
}
|
2017-11-06 16:23:07 +01:00
|
|
|
|
|
|
|
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",
|
2017-07-23 20:12:17 +02:00
|
|
|
},
|
2017-11-06 16:23:07 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, checkpoint stack.Checkpoint) {
|
|
|
|
// Simple runtime validation that just ensures the checkpoint was written and read.
|
2017-12-03 14:38:31 +01:00
|
|
|
assert.Equal(t, minimal.StackName(), checkpoint.Stack)
|
2017-11-06 16:23:07 +01:00
|
|
|
},
|
2017-11-14 18:33:22 +01:00
|
|
|
ReportStats: integration.NewS3Reporter("us-west-2", "eng.pulumi.com", "testreports"),
|
2017-11-06 16:23:07 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 20:26:41 +01:00
|
|
|
var formattableStdout, formattableStderr bytes.Buffer
|
2017-11-06 16:23:07 +01:00
|
|
|
examples := []integration.ProgramTestOptions{
|
|
|
|
minimal,
|
2017-10-12 00:27:34 +02:00
|
|
|
{
|
2017-10-14 02:48:54 +02:00
|
|
|
Dir: path.Join(cwd, "dynamic-provider/simple"),
|
2017-10-12 00:27:34 +02:00
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
Config: map[string]string{
|
2017-10-05 23:08:35 +02:00
|
|
|
"simple:config:w": "1",
|
|
|
|
"simple:config:x": "1",
|
|
|
|
"simple:config:y": "1",
|
2017-10-12 00:27:34 +02:00
|
|
|
},
|
|
|
|
},
|
2017-10-26 20:30:25 +02:00
|
|
|
{
|
|
|
|
Dir: path.Join(cwd, "dynamic-provider/multiple-turns"),
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
},
|
2017-11-14 20:26:41 +01:00
|
|
|
{
|
|
|
|
Dir: path.Join(cwd, "formattable"),
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
ExtraRuntimeValidation: func(t *testing.T, checkpoint stack.Checkpoint) {
|
|
|
|
// 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,
|
|
|
|
},
|
2017-07-23 20:12:17 +02:00
|
|
|
}
|
2017-11-06 16:23:07 +01:00
|
|
|
|
2017-07-23 20:12:17 +02:00
|
|
|
for _, ex := range examples {
|
|
|
|
example := ex
|
2017-08-06 17:26:20 +02:00
|
|
|
t.Run(example.Dir, func(t *testing.T) {
|
2017-10-23 04:03:08 +02:00
|
|
|
integration.ProgramTest(t, example)
|
2017-07-23 20:12:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|