github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/transform_provisioner_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/dag"
     8  )
     9  
    10  func TestMissingProvisionerTransformer(t *testing.T) {
    11  	mod := testModule(t, "transform-provisioner-basic")
    12  
    13  	g := Graph{Path: RootModulePath}
    14  	{
    15  		tf := &ConfigTransformer{Module: mod}
    16  		if err := tf.Transform(&g); err != nil {
    17  			t.Fatalf("err: %s", err)
    18  		}
    19  	}
    20  
    21  	{
    22  		transform := &MissingProvisionerTransformer{Provisioners: []string{"foo"}}
    23  		if err := transform.Transform(&g); err != nil {
    24  			t.Fatalf("err: %s", err)
    25  		}
    26  	}
    27  
    28  	{
    29  		transform := &CloseProvisionerTransformer{}
    30  		if err := transform.Transform(&g); err != nil {
    31  			t.Fatalf("err: %s", err)
    32  		}
    33  	}
    34  
    35  	actual := strings.TrimSpace(g.String())
    36  	expected := strings.TrimSpace(testTransformMissingProvisionerBasicStr)
    37  	if actual != expected {
    38  		t.Fatalf("bad:\n\n%s", actual)
    39  	}
    40  }
    41  
    42  func TestPruneProvisionerTransformer(t *testing.T) {
    43  	mod := testModule(t, "transform-provisioner-prune")
    44  
    45  	g := Graph{Path: RootModulePath}
    46  	{
    47  		tf := &ConfigTransformer{Module: mod}
    48  		if err := tf.Transform(&g); err != nil {
    49  			t.Fatalf("err: %s", err)
    50  		}
    51  	}
    52  
    53  	{
    54  		transform := &MissingProvisionerTransformer{
    55  			Provisioners: []string{"foo", "bar"}}
    56  		if err := transform.Transform(&g); err != nil {
    57  			t.Fatalf("err: %s", err)
    58  		}
    59  	}
    60  
    61  	{
    62  		transform := &ProvisionerTransformer{}
    63  		if err := transform.Transform(&g); err != nil {
    64  			t.Fatalf("err: %s", err)
    65  		}
    66  	}
    67  
    68  	{
    69  		transform := &CloseProvisionerTransformer{}
    70  		if err := transform.Transform(&g); err != nil {
    71  			t.Fatalf("err: %s", err)
    72  		}
    73  	}
    74  
    75  	{
    76  		transform := &PruneProvisionerTransformer{}
    77  		if err := transform.Transform(&g); err != nil {
    78  			t.Fatalf("err: %s", err)
    79  		}
    80  	}
    81  
    82  	actual := strings.TrimSpace(g.String())
    83  	expected := strings.TrimSpace(testTransformPruneProvisionerBasicStr)
    84  	if actual != expected {
    85  		t.Fatalf("bad:\n\n%s", actual)
    86  	}
    87  }
    88  
    89  func TestGraphNodeMissingProvisioner_impl(t *testing.T) {
    90  	var _ dag.Vertex = new(graphNodeMissingProvisioner)
    91  	var _ dag.NamedVertex = new(graphNodeMissingProvisioner)
    92  	var _ GraphNodeProvisioner = new(graphNodeMissingProvisioner)
    93  }
    94  
    95  func TestGraphNodeMissingProvisioner_ProvisionerName(t *testing.T) {
    96  	n := &graphNodeMissingProvisioner{ProvisionerNameValue: "foo"}
    97  	if v := n.ProvisionerName(); v != "foo" {
    98  		t.Fatalf("bad: %#v", v)
    99  	}
   100  }
   101  
   102  const testTransformMissingProvisionerBasicStr = `
   103  aws_instance.web
   104  provisioner.foo
   105  provisioner.shell (close)
   106    aws_instance.web
   107  `
   108  
   109  const testTransformPruneProvisionerBasicStr = `
   110  aws_instance.web
   111    provisioner.foo
   112  provisioner.foo
   113  provisioner.foo (close)
   114    aws_instance.web
   115  `