From f4164b5322aa3970bc88b6a8d77a6e68515a89ca Mon Sep 17 00:00:00 2001 From: James Nugent Date: Tue, 10 Nov 2015 10:15:41 -0500 Subject: [PATCH] Add resource with heredoc to config load tests This test reproduces the issue which is likely the root cause of #3840. Test is currently failing with an "illegal character" message corresponding with the location of the heredoc, which is also seen in various acceptance tests for providers. --- config/loader_test.go | 39 +++++++++++++++++++++++++++++++++ config/test-fixtures/heredoc.tf | 24 ++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 config/test-fixtures/heredoc.tf diff --git a/config/loader_test.go b/config/loader_test.go index eaf4f10aa..18b26f9c5 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -45,6 +45,31 @@ func TestLoadFile_badType(t *testing.T) { } } +func TestLoadFileHeredoc(t *testing.T) { + c, err := LoadFile(filepath.Join(fixtureDir, "heredoc.tf")) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + + actual := providerConfigsStr(c.ProviderConfigs) + if actual != strings.TrimSpace(heredocProvidersStr) { + t.Fatalf("bad:\n%s", actual) + } + + actual = resourcesStr(c.Resources) + if actual != strings.TrimSpace(heredocResourcesStr) { + t.Fatalf("bad:\n%s", actual) + } +} + func TestLoadFileBasic(t *testing.T) { c, err := LoadFile(filepath.Join(fixtureDir, "basic.tf")) if err != nil { @@ -532,6 +557,20 @@ func TestLoad_temporary_files(t *testing.T) { } } +const heredocProvidersStr = ` +aws + access_key + secret_key +` + +const heredocResourcesStr = ` +aws_iam_policy[policy] (x1) + description + name + path + policy +` + const basicOutputsStr = ` web_ip vars diff --git a/config/test-fixtures/heredoc.tf b/config/test-fixtures/heredoc.tf new file mode 100644 index 000000000..b765a58f0 --- /dev/null +++ b/config/test-fixtures/heredoc.tf @@ -0,0 +1,24 @@ +provider "aws" { + access_key = "foo" + secret_key = "bar" +} + +resource "aws_iam_policy" "policy" { + name = "test_policy" + path = "/" + description = "My test policy" + policy = <