mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
99 lines
2.3 KiB
Go
99 lines
2.3 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGraph(t *testing.T) {
|
|
config := testConfig(t, "graph-basic")
|
|
|
|
g := Graph(config, nil)
|
|
if err := g.Validate(); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testTerraformGraphStr)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
func TestGraph_cycle(t *testing.T) {
|
|
config := testConfig(t, "graph-cycle")
|
|
|
|
g := Graph(config, nil)
|
|
if err := g.Validate(); err == nil {
|
|
t.Fatal("should error")
|
|
}
|
|
}
|
|
|
|
func TestGraph_state(t *testing.T) {
|
|
config := testConfig(t, "graph-basic")
|
|
state := &State{
|
|
Resources: map[string]*ResourceState{
|
|
"aws_instance.old": &ResourceState{
|
|
ID: "foo",
|
|
Type: "aws_instance",
|
|
},
|
|
},
|
|
}
|
|
|
|
g := Graph(config, state)
|
|
if err := g.Validate(); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testTerraformGraphStateStr)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|
|
|
|
const testTerraformGraphStr = `
|
|
root: root
|
|
aws_instance.web
|
|
aws_instance.web -> aws_security_group.firewall
|
|
aws_instance.web -> provider.aws
|
|
aws_load_balancer.weblb
|
|
aws_load_balancer.weblb -> aws_instance.web
|
|
aws_load_balancer.weblb -> provider.aws
|
|
aws_security_group.firewall
|
|
aws_security_group.firewall -> provider.aws
|
|
openstack_floating_ip.random
|
|
provider.aws
|
|
provider.aws -> openstack_floating_ip.random
|
|
root
|
|
root -> aws_instance.web
|
|
root -> aws_load_balancer.weblb
|
|
root -> aws_security_group.firewall
|
|
root -> openstack_floating_ip.random
|
|
root -> provider.aws
|
|
`
|
|
|
|
const testTerraformGraphStateStr = `
|
|
root: root
|
|
aws_instance.old
|
|
aws_instance.old -> provider.aws
|
|
aws_instance.web
|
|
aws_instance.web -> aws_security_group.firewall
|
|
aws_instance.web -> provider.aws
|
|
aws_load_balancer.weblb
|
|
aws_load_balancer.weblb -> aws_instance.web
|
|
aws_load_balancer.weblb -> provider.aws
|
|
aws_security_group.firewall
|
|
aws_security_group.firewall -> provider.aws
|
|
openstack_floating_ip.random
|
|
provider.aws
|
|
provider.aws -> openstack_floating_ip.random
|
|
root
|
|
root -> aws_instance.old
|
|
root -> aws_instance.web
|
|
root -> aws_load_balancer.weblb
|
|
root -> aws_security_group.firewall
|
|
root -> openstack_floating_ip.random
|
|
root -> provider.aws
|
|
`
|