github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/terraform/transform_destroy_cbd_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestCBDEdgeTransformer(t *testing.T) { 9 g := Graph{Path: RootModulePath} 10 g.Add(&graphNodeCreatorTest{AddrString: "test.A"}) 11 g.Add(&graphNodeCreatorTest{AddrString: "test.B"}) 12 g.Add(&graphNodeDestroyerTest{AddrString: "test.A", CBD: true}) 13 14 module := testModule(t, "transform-destroy-edge-basic") 15 16 { 17 tf := &DestroyEdgeTransformer{ 18 Module: module, 19 } 20 if err := tf.Transform(&g); err != nil { 21 t.Fatalf("err: %s", err) 22 } 23 } 24 25 { 26 tf := &CBDEdgeTransformer{Module: module} 27 if err := tf.Transform(&g); err != nil { 28 t.Fatalf("err: %s", err) 29 } 30 } 31 32 actual := strings.TrimSpace(g.String()) 33 expected := strings.TrimSpace(testTransformCBDEdgeBasicStr) 34 if actual != expected { 35 t.Fatalf("bad:\n\n%s", actual) 36 } 37 } 38 39 func TestCBDEdgeTransformer_depNonCBD(t *testing.T) { 40 g := Graph{Path: RootModulePath} 41 g.Add(&graphNodeCreatorTest{AddrString: "test.A"}) 42 g.Add(&graphNodeCreatorTest{AddrString: "test.B"}) 43 g.Add(&graphNodeDestroyerTest{AddrString: "test.A"}) 44 g.Add(&graphNodeDestroyerTest{AddrString: "test.B", CBD: true}) 45 46 module := testModule(t, "transform-destroy-edge-basic") 47 48 { 49 tf := &DestroyEdgeTransformer{ 50 Module: module, 51 } 52 if err := tf.Transform(&g); err != nil { 53 t.Fatalf("err: %s", err) 54 } 55 } 56 57 { 58 tf := &CBDEdgeTransformer{Module: module} 59 if err := tf.Transform(&g); err != nil { 60 t.Fatalf("err: %s", err) 61 } 62 } 63 64 actual := strings.TrimSpace(g.String()) 65 expected := strings.TrimSpace(testTransformCBDEdgeDepNonCBDStr) 66 if actual != expected { 67 t.Fatalf("bad:\n\n%s", actual) 68 } 69 } 70 71 const testTransformCBDEdgeBasicStr = ` 72 test.A 73 test.A (destroy) 74 test.A 75 test.B 76 test.B 77 ` 78 79 const testTransformCBDEdgeDepNonCBDStr = ` 80 test.A 81 test.A (destroy) (modified) 82 test.A 83 test.B 84 test.B (destroy) 85 test.B 86 test.B (destroy) 87 test.B 88 `