2018-03-21 20:43:21 +01:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
2017-07-23 20:12:17 +02:00
|
|
|
|
|
|
|
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-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"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2017-11-06 16:23:07 +01:00
|
|
|
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-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
2017-11-06 16:23:07 +01:00
|
|
|
// Simple runtime validation that just ensures the checkpoint was written and read.
|
2018-04-03 06:34:54 +02:00
|
|
|
assert.NotNil(t, stackInfo.Deployment)
|
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"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2017-10-12 00:27:34 +02:00
|
|
|
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"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2018-01-19 23:17:28 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
2018-04-03 06:34:54 +02:00
|
|
|
for _, res := range stackInfo.Deployment.Resources {
|
2018-01-19 23:17:28 +01:00
|
|
|
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 20:30:25 +02:00
|
|
|
},
|
2018-01-22 20:47:14 +01:00
|
|
|
{
|
|
|
|
Dir: path.Join(cwd, "dynamic-provider/derived-inputs"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2018-01-22 20:47:14 +01:00
|
|
|
},
|
2017-11-14 20:26:41 +01:00
|
|
|
{
|
|
|
|
Dir: path.Join(cwd, "formattable"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
2017-11-14 20:26:41 +01: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,
|
|
|
|
},
|
2018-02-06 01:29:20 +01:00
|
|
|
{
|
|
|
|
Dir: path.Join(cwd, "dynamic-provider/multiple-turns-2"),
|
2018-02-12 22:13:13 +01:00
|
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
2018-02-06 01:29:20 +01:00
|
|
|
},
|
2018-03-14 05:52:16 +01:00
|
|
|
{
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
2017-07-23 20:12:17 +02:00
|
|
|
}
|
2017-11-06 16:23:07 +01:00
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
for _, example := range examples {
|
2018-05-29 20:24:51 +02:00
|
|
|
ex := example
|
2017-08-06 17:26:20 +02:00
|
|
|
t.Run(example.Dir, func(t *testing.T) {
|
2018-04-03 06:34:54 +02:00
|
|
|
integration.ProgramTest(t, &ex)
|
2017-07-23 20:12:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|