mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTargetsTransformer(t *testing.T) {
|
|
mod := testModule(t, "transform-targets-basic")
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
{
|
|
tf := &ConfigTransformerOld{Module: mod}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
{
|
|
transform := &TargetsTransformer{Targets: []string{"aws_instance.me"}}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
aws_instance.me
|
|
aws_subnet.me
|
|
aws_subnet.me
|
|
aws_vpc.me
|
|
aws_vpc.me
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\nexpected:\n%s\n\ngot:\n%s\n", expected, actual)
|
|
}
|
|
}
|
|
|
|
func TestTargetsTransformer_destroy(t *testing.T) {
|
|
mod := testModule(t, "transform-targets-destroy")
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
{
|
|
tf := &ConfigTransformerOld{Module: mod}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
{
|
|
transform := &TargetsTransformer{
|
|
Targets: []string{"aws_instance.me"},
|
|
Destroy: true,
|
|
}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
aws_elb.me
|
|
aws_instance.me
|
|
aws_instance.me
|
|
aws_instance.metoo
|
|
aws_instance.me
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\nexpected:\n%s\n\ngot:\n%s\n", expected, actual)
|
|
}
|
|
}
|