github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/terraform/transform_root_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestRootTransformer(t *testing.T) { 9 mod := testModule(t, "transform-root-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 := &MissingProviderTransformer{ 21 Providers: []string{"aws", "do"}, 22 } 23 if err := transform.Transform(&g); err != nil { 24 t.Fatalf("err: %s", err) 25 } 26 } 27 28 { 29 transform := &ProviderTransformer{} 30 if err := transform.Transform(&g); err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 } 34 35 { 36 transform := &RootTransformer{} 37 if err := transform.Transform(&g); err != nil { 38 t.Fatalf("err: %s", err) 39 } 40 } 41 42 actual := strings.TrimSpace(g.String()) 43 expected := strings.TrimSpace(testTransformRootBasicStr) 44 if actual != expected { 45 t.Fatalf("bad:\n\n%s", actual) 46 } 47 48 root, err := g.Root() 49 if err != nil { 50 t.Fatalf("err: %s", err) 51 } 52 if _, ok := root.(graphNodeRoot); !ok { 53 t.Fatalf("bad: %#v", root) 54 } 55 } 56 57 const testTransformRootBasicStr = ` 58 aws_instance.foo 59 provider.aws 60 do_droplet.bar 61 provider.do 62 provider.aws 63 provider.do 64 root 65 aws_instance.foo 66 do_droplet.bar 67 `