2015-01-27 23:48:46 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2015-01-28 00:14:01 -06:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/dag"
|
2015-01-27 23:48:46 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProviderTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-basic")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
transform := &ProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformProviderBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
func TestCloseProviderTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-basic")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &ProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &CloseProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformCloseProviderBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 00:14:01 -06:00
|
|
|
func TestMissingProviderTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-basic")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
{
|
|
|
|
transform := &MissingProviderTransformer{Providers: []string{"foo"}}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &CloseProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2015-01-28 00:14:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformMissingProviderBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 15:03:12 -06:00
|
|
|
func TestPruneProviderTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-prune")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &MissingProviderTransformer{Providers: []string{"foo"}}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &ProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
{
|
|
|
|
transform := &CloseProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 15:03:12 -06:00
|
|
|
{
|
|
|
|
transform := &PruneProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformPruneProviderBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:14:19 -05:00
|
|
|
func TestDisableProviderTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-disable")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &MissingProviderTransformer{Providers: []string{"aws"}}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &ProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
{
|
|
|
|
transform := &CloseProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:14:19 -05:00
|
|
|
{
|
|
|
|
transform := &PruneProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &DisableProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformDisableProviderBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:39:56 -05:00
|
|
|
func TestDisableProviderTransformer_keep(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-provider-disable-keep")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &MissingProviderTransformer{Providers: []string{"aws"}}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &ProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
{
|
|
|
|
transform := &CloseProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:39:56 -05:00
|
|
|
{
|
|
|
|
transform := &PruneProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &DisableProviderTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformDisableProviderKeepStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 00:14:01 -06:00
|
|
|
func TestGraphNodeMissingProvider_impl(t *testing.T) {
|
|
|
|
var _ dag.Vertex = new(graphNodeMissingProvider)
|
|
|
|
var _ dag.NamedVertex = new(graphNodeMissingProvider)
|
|
|
|
var _ GraphNodeProvider = new(graphNodeMissingProvider)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGraphNodeMissingProvider_ProviderName(t *testing.T) {
|
|
|
|
n := &graphNodeMissingProvider{ProviderNameValue: "foo"}
|
|
|
|
if v := n.ProviderName(); v != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:48:46 -06:00
|
|
|
const testTransformProviderBasicStr = `
|
|
|
|
aws_instance.web
|
|
|
|
provider.aws
|
|
|
|
provider.aws
|
|
|
|
`
|
2015-01-28 00:14:01 -06:00
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
const testTransformCloseProviderBasicStr = `
|
|
|
|
aws_instance.web
|
|
|
|
provider.aws
|
|
|
|
provider.aws
|
|
|
|
provider.aws (close)
|
|
|
|
aws_instance.web
|
|
|
|
`
|
|
|
|
|
2015-01-28 00:14:01 -06:00
|
|
|
const testTransformMissingProviderBasicStr = `
|
|
|
|
aws_instance.web
|
|
|
|
provider.aws
|
2015-06-19 14:52:50 -05:00
|
|
|
provider.aws (close)
|
|
|
|
aws_instance.web
|
2015-01-28 00:14:01 -06:00
|
|
|
provider.foo
|
|
|
|
`
|
2015-01-30 15:03:12 -06:00
|
|
|
|
|
|
|
const testTransformPruneProviderBasicStr = `
|
|
|
|
foo_instance.web
|
|
|
|
provider.foo
|
|
|
|
provider.foo
|
2015-06-19 14:52:50 -05:00
|
|
|
provider.foo (close)
|
|
|
|
foo_instance.web
|
2015-01-30 15:03:12 -06:00
|
|
|
`
|
2015-04-08 23:14:19 -05:00
|
|
|
|
|
|
|
const testTransformDisableProviderBasicStr = `
|
|
|
|
module.child
|
2015-04-09 10:51:38 -05:00
|
|
|
provider.aws (disabled)
|
2015-04-30 18:27:20 -05:00
|
|
|
var.foo
|
2015-06-19 14:52:50 -05:00
|
|
|
provider.aws (close)
|
|
|
|
module.child
|
2015-04-09 10:51:38 -05:00
|
|
|
provider.aws (disabled)
|
2015-04-30 18:27:20 -05:00
|
|
|
var.foo
|
2015-04-08 23:14:19 -05:00
|
|
|
`
|
2015-04-08 23:39:56 -05:00
|
|
|
|
|
|
|
const testTransformDisableProviderKeepStr = `
|
|
|
|
aws_instance.foo
|
|
|
|
provider.aws
|
|
|
|
module.child
|
|
|
|
provider.aws
|
2015-04-30 18:27:20 -05:00
|
|
|
var.foo
|
2015-04-08 23:39:56 -05:00
|
|
|
provider.aws
|
2015-06-19 14:52:50 -05:00
|
|
|
provider.aws (close)
|
|
|
|
aws_instance.foo
|
|
|
|
module.child
|
2015-04-30 18:27:20 -05:00
|
|
|
var.foo
|
2015-04-08 23:39:56 -05:00
|
|
|
`
|