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