github.com/federicobaldo/terraform@v0.6.15-0.20160323222747-b20f680cbf05/terraform/transform_tainted_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/terraform/dag" 8 ) 9 10 func TestTaintedTransformer(t *testing.T) { 11 mod := testModule(t, "transform-tainted-basic") 12 state := &State{ 13 Modules: []*ModuleState{ 14 &ModuleState{ 15 Path: RootModulePath, 16 Resources: map[string]*ResourceState{ 17 "aws_instance.web": &ResourceState{ 18 Type: "aws_instance", 19 Tainted: []*InstanceState{ 20 &InstanceState{ID: "foo"}, 21 }, 22 }, 23 }, 24 }, 25 }, 26 } 27 28 g := Graph{Path: RootModulePath} 29 { 30 tf := &ConfigTransformer{Module: mod} 31 if err := tf.Transform(&g); err != nil { 32 t.Fatalf("err: %s", err) 33 } 34 } 35 36 transform := &TaintedTransformer{State: state} 37 if err := transform.Transform(&g); err != nil { 38 t.Fatalf("err: %s", err) 39 } 40 41 actual := strings.TrimSpace(g.String()) 42 expected := strings.TrimSpace(testTransformTaintedBasicStr) 43 if actual != expected { 44 t.Fatalf("bad:\n\n%s", actual) 45 } 46 } 47 48 func TestGraphNodeTaintedResource_impl(t *testing.T) { 49 var _ dag.Vertex = new(graphNodeTaintedResource) 50 var _ dag.NamedVertex = new(graphNodeTaintedResource) 51 var _ GraphNodeProviderConsumer = new(graphNodeTaintedResource) 52 } 53 54 func TestGraphNodeTaintedResource_ProvidedBy(t *testing.T) { 55 n := &graphNodeTaintedResource{ResourceName: "aws_instance.foo"} 56 if v := n.ProvidedBy(); v[0] != "aws" { 57 t.Fatalf("bad: %#v", v) 58 } 59 } 60 61 func TestGraphNodeTaintedResource_ProvidedBy_alias(t *testing.T) { 62 n := &graphNodeTaintedResource{ResourceName: "aws_instance.foo", Provider: "aws.bar"} 63 if v := n.ProvidedBy(); v[0] != "aws.bar" { 64 t.Fatalf("bad: %#v", v) 65 } 66 } 67 68 const testTransformTaintedBasicStr = ` 69 aws_instance.web 70 aws_instance.web (tainted #1) 71 `