From 492bda5186aa01068e0b561ba495a8fbd4e95a1b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 30 Apr 2016 08:57:21 +0200 Subject: [PATCH] terraform: more provider transform tests --- terraform/transform_provider_test.go | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/terraform/transform_provider_test.go b/terraform/transform_provider_test.go index c9b08db58..85a6266f9 100644 --- a/terraform/transform_provider_test.go +++ b/terraform/transform_provider_test.go @@ -30,6 +30,44 @@ func TestProviderTransformer(t *testing.T) { } } +func TestProviderTransformer_moduleChild(t *testing.T) { + g := Graph{Path: RootModulePath} + + { + tf := &ImportStateTransformer{ + Targets: []*ImportTarget{ + &ImportTarget{ + Addr: "module.moo.foo_instance.qux", + ID: "bar", + }, + }, + } + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + } + + { + tf := &MissingProviderTransformer{Providers: []string{"foo", "bar"}} + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + } + + { + tf := &ProviderTransformer{} + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTransformProviderModuleChildStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + func TestCloseProviderTransformer(t *testing.T) { mod := testModule(t, "transform-provider-basic") @@ -158,6 +196,40 @@ func TestMissingProviderTransformer_moduleChild(t *testing.T) { } } +func TestMissingProviderTransformer_moduleGrandchild(t *testing.T) { + g := Graph{Path: RootModulePath} + + // We use the import state transformer since at the time of writing + // this test it is the first and only transformer that will introduce + // multiple module-path nodes at a single go. + { + tf := &ImportStateTransformer{ + Targets: []*ImportTarget{ + &ImportTarget{ + Addr: "module.a.module.b.foo_instance.qux", + ID: "bar", + }, + }, + } + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + } + + { + tf := &MissingProviderTransformer{Providers: []string{"foo", "bar"}} + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTransformMissingProviderModuleGrandchildStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + func TestPruneProviderTransformer(t *testing.T) { mod := testModule(t, "transform-provider-prune") @@ -303,6 +375,20 @@ module.moo.provider.foo provider.foo ` +const testTransformMissingProviderModuleGrandchildStr = ` +module.a.module.b.foo_instance.qux (import id: bar) +module.a.module.b.provider.foo +module.a.provider.foo +provider.foo +` + +const testTransformProviderModuleChildStr = ` +module.moo.foo_instance.qux (import id: bar) + module.moo.provider.foo +module.moo.provider.foo +provider.foo +` + const testTransformPruneProviderBasicStr = ` foo_instance.web provider.foo