github.com/federicobaldo/terraform@v0.6.15-0.20160323222747-b20f680cbf05/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{"shell"}} 23 if err := transform.Transform(&g); err != nil { 24 t.Fatalf("err: %s", err) 25 } 26 } 27 28 { 29 transform := &ProvisionerTransformer{} 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 TestCloseProvisionerTransformer(t *testing.T) { 43 mod := testModule(t, "transform-provisioner-basic") 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{Provisioners: []string{"shell"}} 55 if err := transform.Transform(&g); err != nil { 56 t.Fatalf("err: %s", err) 57 } 58 } 59 60 { 61 transform := &ProvisionerTransformer{} 62 if err := transform.Transform(&g); err != nil { 63 t.Fatalf("err: %s", err) 64 } 65 } 66 67 { 68 transform := &CloseProvisionerTransformer{} 69 if err := transform.Transform(&g); err != nil { 70 t.Fatalf("err: %s", err) 71 } 72 } 73 74 actual := strings.TrimSpace(g.String()) 75 expected := strings.TrimSpace(testTransformCloseProvisionerBasicStr) 76 if actual != expected { 77 t.Fatalf("bad:\n\n%s", actual) 78 } 79 } 80 func TestGraphNodeProvisioner_impl(t *testing.T) { 81 var _ dag.Vertex = new(graphNodeProvisioner) 82 var _ dag.NamedVertex = new(graphNodeProvisioner) 83 var _ GraphNodeProvisioner = new(graphNodeProvisioner) 84 } 85 86 func TestGraphNodeProvisioner_ProvisionerName(t *testing.T) { 87 n := &graphNodeProvisioner{ProvisionerNameValue: "foo"} 88 if v := n.ProvisionerName(); v != "foo" { 89 t.Fatalf("bad: %#v", v) 90 } 91 } 92 93 const testTransformMissingProvisionerBasicStr = ` 94 aws_instance.web 95 provisioner.shell 96 provisioner.shell 97 ` 98 99 const testTransformCloseProvisionerBasicStr = ` 100 aws_instance.web 101 provisioner.shell 102 provisioner.shell 103 provisioner.shell (close) 104 aws_instance.web 105 `