github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/terraform/transform_provider_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/terraform/dag" 8 ) 9 10 func TestProviderTransformer(t *testing.T) { 11 mod := testModule(t, "transform-provider-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 transform := &ProviderTransformer{} 22 if err := transform.Transform(&g); err != nil { 23 t.Fatalf("err: %s", err) 24 } 25 26 actual := strings.TrimSpace(g.String()) 27 expected := strings.TrimSpace(testTransformProviderBasicStr) 28 if actual != expected { 29 t.Fatalf("bad:\n\n%s", actual) 30 } 31 } 32 33 func TestMissingProviderTransformer(t *testing.T) { 34 mod := testModule(t, "transform-provider-basic") 35 36 g := Graph{Path: RootModulePath} 37 { 38 tf := &ConfigTransformer{Module: mod} 39 if err := tf.Transform(&g); err != nil { 40 t.Fatalf("err: %s", err) 41 } 42 } 43 44 transform := &MissingProviderTransformer{Providers: []string{"foo"}} 45 if err := transform.Transform(&g); err != nil { 46 t.Fatalf("err: %s", err) 47 } 48 49 actual := strings.TrimSpace(g.String()) 50 expected := strings.TrimSpace(testTransformMissingProviderBasicStr) 51 if actual != expected { 52 t.Fatalf("bad:\n\n%s", actual) 53 } 54 } 55 56 func TestPruneProviderTransformer(t *testing.T) { 57 mod := testModule(t, "transform-provider-prune") 58 59 g := Graph{Path: RootModulePath} 60 { 61 tf := &ConfigTransformer{Module: mod} 62 if err := tf.Transform(&g); err != nil { 63 t.Fatalf("err: %s", err) 64 } 65 } 66 67 { 68 transform := &MissingProviderTransformer{Providers: []string{"foo"}} 69 if err := transform.Transform(&g); err != nil { 70 t.Fatalf("err: %s", err) 71 } 72 } 73 74 { 75 transform := &ProviderTransformer{} 76 if err := transform.Transform(&g); err != nil { 77 t.Fatalf("err: %s", err) 78 } 79 } 80 81 { 82 transform := &PruneProviderTransformer{} 83 if err := transform.Transform(&g); err != nil { 84 t.Fatalf("err: %s", err) 85 } 86 } 87 88 actual := strings.TrimSpace(g.String()) 89 expected := strings.TrimSpace(testTransformPruneProviderBasicStr) 90 if actual != expected { 91 t.Fatalf("bad:\n\n%s", actual) 92 } 93 } 94 95 func TestGraphNodeMissingProvider_impl(t *testing.T) { 96 var _ dag.Vertex = new(graphNodeMissingProvider) 97 var _ dag.NamedVertex = new(graphNodeMissingProvider) 98 var _ GraphNodeProvider = new(graphNodeMissingProvider) 99 } 100 101 func TestGraphNodeMissingProvider_ProviderName(t *testing.T) { 102 n := &graphNodeMissingProvider{ProviderNameValue: "foo"} 103 if v := n.ProviderName(); v != "foo" { 104 t.Fatalf("bad: %#v", v) 105 } 106 } 107 108 const testTransformProviderBasicStr = ` 109 aws_instance.web 110 provider.aws 111 provider.aws 112 ` 113 114 const testTransformMissingProviderBasicStr = ` 115 aws_instance.web 116 provider.aws 117 provider.foo 118 ` 119 120 const testTransformPruneProviderBasicStr = ` 121 foo_instance.web 122 provider.foo 123 provider.foo 124 `