2017-11-16 16:49:07 +01:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
|
|
|
package ints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2017-12-08 22:14:58 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
2017-11-16 16:49:07 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource/stack"
|
2017-11-30 17:14:47 +01:00
|
|
|
ptesting "github.com/pulumi/pulumi/pkg/testing"
|
2017-11-16 16:49:07 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/testing/integration"
|
|
|
|
)
|
|
|
|
|
2017-11-16 17:15:56 +01:00
|
|
|
// TestProjectMain tests out the ability to override the main entrypoint.
|
2017-11-16 16:49:07 +01:00
|
|
|
func TestProjectMain(t *testing.T) {
|
|
|
|
var test integration.ProgramTestOptions
|
|
|
|
test = integration.ProgramTestOptions{
|
|
|
|
Dir: "project_main",
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
ExtraRuntimeValidation: func(t *testing.T, checkpoint stack.Checkpoint) {
|
|
|
|
// Simple runtime validation that just ensures the checkpoint was written and read.
|
2017-12-05 22:01:54 +01:00
|
|
|
assert.Equal(t, test.StackName(), checkpoint.Stack)
|
2017-11-16 16:49:07 +01:00
|
|
|
},
|
|
|
|
}
|
2017-12-09 01:59:28 +01:00
|
|
|
integration.ProgramTest(t, &test)
|
2017-11-30 17:14:47 +01:00
|
|
|
|
|
|
|
t.Run("Error_AbsolutePath", func(t *testing.T) {
|
|
|
|
e := ptesting.NewEnvironment(t)
|
|
|
|
defer func() {
|
|
|
|
if !t.Failed() {
|
|
|
|
e.DeleteEnvironment()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
e.RunCommand("git", "init")
|
|
|
|
e.RunCommand("pulumi", "init")
|
|
|
|
|
|
|
|
e.ImportDirectory("project_main_abs")
|
2017-12-03 14:38:31 +01:00
|
|
|
e.RunCommand("pulumi", "stack", "init", "--local", "main-abs")
|
2017-11-30 17:14:47 +01:00
|
|
|
stdout, stderr := e.RunCommandExpectError("pulumi", "update")
|
|
|
|
assert.Equal(t, "", stdout)
|
|
|
|
assert.Contains(t, stderr, "project 'main' must be a relative path")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Error_ParentFolder", func(t *testing.T) {
|
|
|
|
e := ptesting.NewEnvironment(t)
|
|
|
|
defer func() {
|
|
|
|
if !t.Failed() {
|
|
|
|
e.DeleteEnvironment()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
e.RunCommand("git", "init")
|
|
|
|
e.RunCommand("pulumi", "init")
|
|
|
|
|
|
|
|
e.ImportDirectory("project_main_parent")
|
2017-12-03 14:38:31 +01:00
|
|
|
e.RunCommand("pulumi", "stack", "init", "--local", "main-parent")
|
2017-11-30 17:14:47 +01:00
|
|
|
stdout, stderr := e.RunCommandExpectError("pulumi", "update")
|
|
|
|
assert.Equal(t, "", stdout)
|
|
|
|
assert.Contains(t, stderr, "project 'main' must be a subfolder")
|
|
|
|
})
|
2017-11-16 16:49:07 +01:00
|
|
|
}
|
2017-11-16 17:15:56 +01:00
|
|
|
|
|
|
|
// TestStackProjectName ensures we can read the Pulumi stack and project name from within the program.
|
|
|
|
func TestStackProjectName(t *testing.T) {
|
2017-12-09 01:59:28 +01:00
|
|
|
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
2017-11-16 17:15:56 +01:00
|
|
|
Dir: "stack_project_name",
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
Quick: true,
|
2017-12-05 22:01:54 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestStackOutputs ensures we can export variables from a stack and have them get recorded as outputs.
|
|
|
|
func TestStackOutputs(t *testing.T) {
|
2017-12-09 01:59:28 +01:00
|
|
|
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
2017-12-05 22:01:54 +01:00
|
|
|
Dir: "stack_outputs",
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
Quick: true,
|
|
|
|
ExtraRuntimeValidation: func(t *testing.T, checkpoint stack.Checkpoint) {
|
|
|
|
// Ensure the checkpoint contains a single resource, the Stack, with two outputs.
|
|
|
|
assert.NotNil(t, checkpoint.Latest)
|
|
|
|
if assert.Equal(t, 1, len(checkpoint.Latest.Resources)) {
|
|
|
|
stackRes := checkpoint.Latest.Resources[0]
|
|
|
|
assert.NotNil(t, stackRes)
|
2017-12-08 22:14:58 +01:00
|
|
|
assert.Equal(t, resource.RootStackType, stackRes.URN.Type())
|
2017-12-05 22:01:54 +01:00
|
|
|
assert.Equal(t, 0, len(stackRes.Inputs))
|
|
|
|
assert.Equal(t, 2, len(stackRes.Outputs))
|
|
|
|
assert.Equal(t, "ABC", stackRes.Outputs["xyz"])
|
|
|
|
assert.Equal(t, float64(42), stackRes.Outputs["foo"])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2017-11-16 17:15:56 +01:00
|
|
|
}
|
2017-12-06 04:14:28 +01:00
|
|
|
|
|
|
|
// TestStackParenting tests out that stacks and components are parented correctly.
|
|
|
|
func TestStackParenting(t *testing.T) {
|
2017-12-09 01:59:28 +01:00
|
|
|
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
2017-12-06 04:14:28 +01:00
|
|
|
Dir: "stack_parenting",
|
|
|
|
Dependencies: []string{"pulumi"},
|
|
|
|
Quick: true,
|
|
|
|
ExtraRuntimeValidation: func(t *testing.T, checkpoint stack.Checkpoint) {
|
|
|
|
// Ensure the checkpoint contains resources parented correctly. This should look like this:
|
|
|
|
//
|
|
|
|
// A F
|
|
|
|
// / \ \
|
|
|
|
// B C G
|
|
|
|
// / \
|
|
|
|
// D E
|
|
|
|
//
|
|
|
|
// with the caveat, of course, that A and F will share a common parent, the implicit stack.
|
|
|
|
|
|
|
|
assert.NotNil(t, checkpoint.Latest)
|
|
|
|
if assert.Equal(t, 8, len(checkpoint.Latest.Resources)) {
|
|
|
|
stackRes := checkpoint.Latest.Resources[0]
|
|
|
|
assert.NotNil(t, stackRes)
|
2017-12-08 22:14:58 +01:00
|
|
|
assert.Equal(t, resource.RootStackType, stackRes.Type)
|
2017-12-06 04:14:28 +01:00
|
|
|
assert.Equal(t, "", string(stackRes.Parent))
|
|
|
|
a := checkpoint.Latest.Resources[1]
|
|
|
|
assert.NotNil(t, a)
|
|
|
|
assert.Equal(t, "a", string(a.URN.Name()))
|
|
|
|
assert.NotEqual(t, "", a.Parent)
|
|
|
|
assert.Equal(t, stackRes.URN, a.Parent)
|
|
|
|
b := checkpoint.Latest.Resources[2]
|
|
|
|
assert.NotNil(t, b)
|
|
|
|
assert.Equal(t, "b", string(b.URN.Name()))
|
|
|
|
assert.Equal(t, a.URN, b.Parent)
|
|
|
|
c := checkpoint.Latest.Resources[3]
|
|
|
|
assert.NotNil(t, c)
|
|
|
|
assert.Equal(t, "c", string(c.URN.Name()))
|
|
|
|
assert.Equal(t, a.URN, c.Parent)
|
|
|
|
d := checkpoint.Latest.Resources[4]
|
|
|
|
assert.NotNil(t, d)
|
|
|
|
assert.Equal(t, "d", string(d.URN.Name()))
|
|
|
|
assert.Equal(t, c.URN, d.Parent)
|
|
|
|
e := checkpoint.Latest.Resources[5]
|
|
|
|
assert.NotNil(t, e)
|
|
|
|
assert.Equal(t, "e", string(e.URN.Name()))
|
|
|
|
assert.Equal(t, c.URN, e.Parent)
|
|
|
|
f := checkpoint.Latest.Resources[6]
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
assert.Equal(t, "f", string(f.URN.Name()))
|
|
|
|
assert.Equal(t, stackRes.URN, f.Parent)
|
|
|
|
g := checkpoint.Latest.Resources[7]
|
|
|
|
assert.NotNil(t, g)
|
|
|
|
assert.Equal(t, "g", string(g.URN.Name()))
|
|
|
|
assert.Equal(t, f.URN, g.Parent)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|