opentofu/terraform/transform_provisioner_test.go

106 lines
2.3 KiB
Go
Raw Normal View History

2015-02-09 12:14:09 -06:00
package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/dag"
)
func TestMissingProvisionerTransformer(t *testing.T) {
mod := testModule(t, "transform-provisioner-basic")
g := Graph{Path: RootModulePath}
{
tf := &ConfigTransformer{Module: mod}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
transform := &MissingProvisionerTransformer{Provisioners: []string{"shell"}}
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
transform := &ProvisionerTransformer{}
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
2015-02-09 12:14:09 -06:00
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformMissingProvisionerBasicStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestCloseProvisionerTransformer(t *testing.T) {
mod := testModule(t, "transform-provisioner-basic")
2015-02-09 12:14:09 -06:00
g := Graph{Path: RootModulePath}
{
tf := &ConfigTransformer{Module: mod}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
transform := &MissingProvisionerTransformer{Provisioners: []string{"shell"}}
2015-02-09 12:14:09 -06:00
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
transform := &ProvisionerTransformer{}
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
transform := &CloseProvisionerTransformer{}
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
2015-02-09 12:14:09 -06:00
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformCloseProvisionerBasicStr)
2015-02-09 12:14:09 -06:00
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraphNodeProvisioner_impl(t *testing.T) {
var _ dag.Vertex = new(graphNodeProvisioner)
var _ dag.NamedVertex = new(graphNodeProvisioner)
var _ GraphNodeProvisioner = new(graphNodeProvisioner)
2015-02-09 12:14:09 -06:00
}
func TestGraphNodeProvisioner_ProvisionerName(t *testing.T) {
n := &graphNodeProvisioner{ProvisionerNameValue: "foo"}
2015-02-09 12:14:09 -06:00
if v := n.ProvisionerName(); v != "foo" {
t.Fatalf("bad: %#v", v)
}
}
const testTransformMissingProvisionerBasicStr = `
aws_instance.web
provisioner.shell
provisioner.shell
2015-02-09 12:14:09 -06:00
`
const testTransformCloseProvisionerBasicStr = `
2015-02-09 12:14:09 -06:00
aws_instance.web
provisioner.shell
provisioner.shell
provisioner.shell (close)
aws_instance.web
2015-02-09 12:14:09 -06:00
`