terraform: tests for ParentProviderTransformer
This commit is contained in:
parent
87bff933ef
commit
11578f0792
|
@ -285,7 +285,7 @@ func (t *ParentProviderTransformer) Transform(g *Graph) error {
|
|||
|
||||
// Build the key with path.name i.e. "child.subchild.aws"
|
||||
key := fmt.Sprintf("%s.%s", strings.Join(path, "."), pn.ProviderName())
|
||||
m[key] = v
|
||||
m[key] = raw
|
||||
|
||||
// Determine the parent if we're non-root. This is length 1 since
|
||||
// the 0 index should be "root" since we normalize above.
|
||||
|
|
|
@ -230,6 +230,89 @@ func TestMissingProviderTransformer_moduleGrandchild(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParentProviderTransformer(t *testing.T) {
|
||||
g := Graph{Path: RootModulePath}
|
||||
|
||||
// Introduce a cihld module
|
||||
{
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// Add the missing modules
|
||||
{
|
||||
tf := &MissingProviderTransformer{Providers: []string{"foo", "bar"}}
|
||||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect parents
|
||||
{
|
||||
tf := &ParentProviderTransformer{}
|
||||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTransformParentProviderStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParentProviderTransformer_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)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect parents
|
||||
{
|
||||
tf := &ParentProviderTransformer{}
|
||||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTransformParentProviderModuleGrandchildStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPruneProviderTransformer(t *testing.T) {
|
||||
mod := testModule(t, "transform-provider-prune")
|
||||
|
||||
|
@ -382,6 +465,22 @@ module.a.provider.foo
|
|||
provider.foo
|
||||
`
|
||||
|
||||
const testTransformParentProviderStr = `
|
||||
module.moo.foo_instance.qux (import id: bar)
|
||||
module.moo.provider.foo
|
||||
provider.foo
|
||||
provider.foo
|
||||
`
|
||||
|
||||
const testTransformParentProviderModuleGrandchildStr = `
|
||||
module.a.module.b.foo_instance.qux (import id: bar)
|
||||
module.a.module.b.provider.foo
|
||||
module.a.provider.foo
|
||||
module.a.provider.foo
|
||||
provider.foo
|
||||
provider.foo
|
||||
`
|
||||
|
||||
const testTransformProviderModuleChildStr = `
|
||||
module.moo.foo_instance.qux (import id: bar)
|
||||
module.moo.provider.foo
|
||||
|
|
Loading…
Reference in New Issue