terraform: more provider transform tests

This commit is contained in:
Mitchell Hashimoto 2016-04-30 08:57:21 +02:00
parent 0a7f48ab8e
commit 492bda5186
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 86 additions and 0 deletions

View File

@ -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