From 2f2f5890f47b8c0b79ffa14b1a2245e066a4286a Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 11 Jul 2014 11:37:04 -0700 Subject: [PATCH] config: Testing loading of connection blocks --- config/loader_test.go | 52 ++++++++++++++++++++++++++++++ config/test-fixtures/connection.tf | 23 +++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 config/test-fixtures/connection.tf diff --git a/config/loader_test.go b/config/loader_test.go index 4181dcb34..378eb9518 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -185,6 +185,44 @@ func TestLoad_provisioners(t *testing.T) { } } +func TestLoad_connections(t *testing.T) { + c, err := Load(filepath.Join(fixtureDir, "connection.tf")) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + actual := resourcesStr(c.Resources) + if actual != strings.TrimSpace(connectionResourcesStr) { + t.Fatalf("bad:\n%s", actual) + } + + // Check for the connection info + r := c.Resources[0] + if r.Name != "web" && r.Type != "aws_instance" { + t.Fatalf("Bad: %#v", r) + } + + p1 := r.Provisioners[0] + if p1.ConnInfo == nil || len(p1.ConnInfo.Raw) != 2 { + t.Fatalf("Bad: %#v", p1.ConnInfo) + } + if p1.ConnInfo.Raw["user"] != "nobody" { + t.Fatalf("Bad: %#v", p1.ConnInfo) + } + + p2 := r.Provisioners[1] + if p2.ConnInfo == nil || len(p2.ConnInfo.Raw) != 2 { + t.Fatalf("Bad: %#v", p2.ConnInfo) + } + if p2.ConnInfo.Raw["user"] != "root" { + t.Fatalf("Bad: %#v", p2.ConnInfo) + } +} + // This helper turns a provider configs field into a deterministic // string value for comparison in tests. func providerConfigsStr(pcs map[string]*ProviderConfig) string { @@ -448,6 +486,20 @@ aws_instance[web] (x1) user: var.foo ` +const connectionResourcesStr = ` +aws_instance[web] (x1) + ami + security_groups + provisioners + shell + path + shell + path + vars + resource: aws_security_group.firewall.foo + user: var.foo +` + const variablesVariablesStr = ` bar <> diff --git a/config/test-fixtures/connection.tf b/config/test-fixtures/connection.tf new file mode 100644 index 000000000..7f808f2cb --- /dev/null +++ b/config/test-fixtures/connection.tf @@ -0,0 +1,23 @@ +resource "aws_instance" "web" { + ami = "${var.foo}" + security_groups = [ + "foo", + "${aws_security_group.firewall.foo}" + ] + + connection { + type = "ssh" + user = "root" + } + + provisioner "shell" { + path = "foo" + connection { + user = "nobody" + } + } + + provisioner "shell" { + path = "bar" + } +}