mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 01:11:10 -06:00
4a21b763aa
After the refactoring to integrate HCL2 many of the tests were no longer using correct types, attribute names, etc. This is a bulk update of all of the tests to make them compile again, with minimal changes otherwise. Although the tests now compile, many of them do not yet pass. The tests will be gradually repaired in subsequent commits, as we continue to complete the refactoring and retrofit work.
114 lines
2.6 KiB
Go
114 lines
2.6 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
func TestConfigTransformer_nilModule(t *testing.T) {
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
tf := &ConfigTransformer{}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if len(g.Vertices()) > 0 {
|
|
t.Fatalf("graph is not empty: %s", g.String())
|
|
}
|
|
}
|
|
|
|
func TestConfigTransformer(t *testing.T) {
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
tf := &ConfigTransformer{Config: testModule(t, "graph-basic")}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testConfigTransformerGraphBasicStr)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
func TestConfigTransformer_mode(t *testing.T) {
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
tf := &ConfigTransformer{
|
|
Config: testModule(t, "transform-config-mode-data"),
|
|
ModeFilter: true,
|
|
Mode: addrs.DataResourceMode,
|
|
}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
data.aws_ami.foo
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
func TestConfigTransformer_nonUnique(t *testing.T) {
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
g.Add(NewNodeAbstractResource(
|
|
addrs.RootModuleInstance.Resource(
|
|
addrs.ManagedResourceMode, "aws_instance", "web",
|
|
),
|
|
))
|
|
tf := &ConfigTransformer{Config: testModule(t, "graph-basic")}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
aws_instance.web
|
|
aws_instance.web
|
|
aws_load_balancer.weblb
|
|
aws_security_group.firewall
|
|
openstack_floating_ip.random
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
func TestConfigTransformer_unique(t *testing.T) {
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
g.Add(NewNodeAbstractResource(
|
|
addrs.RootModuleInstance.Resource(
|
|
addrs.ManagedResourceMode, "aws_instance", "web",
|
|
),
|
|
))
|
|
tf := &ConfigTransformer{
|
|
Config: testModule(t, "graph-basic"),
|
|
Unique: true,
|
|
}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
aws_instance.web
|
|
aws_load_balancer.weblb
|
|
aws_security_group.firewall
|
|
openstack_floating_ip.random
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
const testConfigTransformerGraphBasicStr = `
|
|
aws_instance.web
|
|
aws_load_balancer.weblb
|
|
aws_security_group.firewall
|
|
openstack_floating_ip.random
|
|
`
|