2014-05-23 01:56:28 +02:00
|
|
|
package config
|
|
|
|
|
2014-05-24 20:41:19 +02:00
|
|
|
import (
|
2014-05-24 22:57:51 +02:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2014-05-24 20:41:19 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-05-23 01:56:28 +02:00
|
|
|
// This is the directory where our test fixtures are.
|
|
|
|
const fixtureDir = "./test-fixtures"
|
2014-05-24 20:41:19 +02:00
|
|
|
|
2014-05-24 22:57:51 +02:00
|
|
|
func TestConfigResourceGraph(t *testing.T) {
|
|
|
|
c, err := Load(filepath.Join(fixtureDir, "resource_graph.tf"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
graph := c.ResourceGraph()
|
|
|
|
if err := graph.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(graph.String())
|
|
|
|
expected := resourceGraphValue
|
|
|
|
|
|
|
|
if actual != strings.TrimSpace(expected) {
|
|
|
|
t.Fatalf("bad:\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:41:19 +02:00
|
|
|
func TestNewResourceVariable(t *testing.T) {
|
|
|
|
v, err := NewResourceVariable("foo.bar.baz")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Type != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
if v.Name != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
if v.Field != "baz" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.FullKey() != "foo.bar.baz" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewUserVariable(t *testing.T) {
|
|
|
|
v, err := NewUserVariable("var.bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Name != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", v.Name)
|
|
|
|
}
|
|
|
|
if v.FullKey() != "var.bar" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 22:57:51 +02:00
|
|
|
|
|
|
|
const resourceGraphValue = `
|
|
|
|
root: root
|
|
|
|
root -> aws_security_group.firewall
|
|
|
|
root -> aws_instance.web
|
2014-05-24 23:02:49 +02:00
|
|
|
root -> aws_load_balancer.weblb
|
2014-05-24 22:57:51 +02:00
|
|
|
aws_security_group.firewall
|
|
|
|
aws_instance.web
|
|
|
|
aws_instance.web -> aws_security_group.firewall
|
2014-05-24 23:02:49 +02:00
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_load_balancer.weblb -> aws_instance.web
|
2014-05-24 22:57:51 +02:00
|
|
|
root
|
|
|
|
root -> aws_security_group.firewall
|
|
|
|
root -> aws_instance.web
|
2014-05-24 23:02:49 +02:00
|
|
|
root -> aws_load_balancer.weblb
|
2014-05-24 22:57:51 +02:00
|
|
|
`
|