github.com/tam7t/terraform@v0.7.0-rc2.0.20160705125922-be2469a05c5e/terraform/transform_targets_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestTargetsTransformer(t *testing.T) { 9 mod := testModule(t, "transform-targets-basic") 10 11 g := Graph{Path: RootModulePath} 12 { 13 tf := &ConfigTransformer{Module: mod} 14 if err := tf.Transform(&g); err != nil { 15 t.Fatalf("err: %s", err) 16 } 17 } 18 19 { 20 transform := &TargetsTransformer{Targets: []string{"aws_instance.me"}} 21 if err := transform.Transform(&g); err != nil { 22 t.Fatalf("err: %s", err) 23 } 24 } 25 26 actual := strings.TrimSpace(g.String()) 27 expected := strings.TrimSpace(` 28 aws_instance.me 29 aws_subnet.me 30 aws_subnet.me 31 aws_vpc.me 32 aws_vpc.me 33 `) 34 if actual != expected { 35 t.Fatalf("bad:\n\nexpected:\n%s\n\ngot:\n%s\n", expected, actual) 36 } 37 } 38 39 func TestTargetsTransformer_destroy(t *testing.T) { 40 mod := testModule(t, "transform-targets-destroy") 41 42 g := Graph{Path: RootModulePath} 43 { 44 tf := &ConfigTransformer{Module: mod} 45 if err := tf.Transform(&g); err != nil { 46 t.Fatalf("err: %s", err) 47 } 48 } 49 50 { 51 transform := &TargetsTransformer{ 52 Targets: []string{"aws_instance.me"}, 53 Destroy: true, 54 } 55 if err := transform.Transform(&g); err != nil { 56 t.Fatalf("err: %s", err) 57 } 58 } 59 60 actual := strings.TrimSpace(g.String()) 61 expected := strings.TrimSpace(` 62 aws_elb.me 63 aws_instance.me 64 aws_instance.me 65 aws_instance.metoo 66 aws_instance.me 67 `) 68 if actual != expected { 69 t.Fatalf("bad:\n\nexpected:\n%s\n\ngot:\n%s\n", expected, actual) 70 } 71 }