From 048af6e237c45709b9d27bc255686f2b4960256e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 22 Nov 2017 10:19:46 -0500 Subject: [PATCH] Add test fixture to check for warnings --- config/config.go | 1 - config/config_test.go | 19 +++++++++++++++ .../test-fixtures/output-no-warnings/main.tf | 6 +++++ config/test-fixtures/output-warnings/main.tf | 24 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 config/test-fixtures/output-no-warnings/main.tf create mode 100644 config/test-fixtures/output-warnings/main.tf diff --git a/config/config.go b/config/config.go index 62f2658440..c89f2ed7c3 100644 --- a/config/config.go +++ b/config/config.go @@ -859,7 +859,6 @@ func (c *Config) Validate() tfdiags.Diagnostics { } } } - } } diff --git a/config/config_test.go b/config/config_test.go index 7f4835c2cc..18bab3f176 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -862,3 +862,22 @@ func TestConfigModuleProviders(t *testing.T) { t.Fatalf("exptected providers %#v, got providers %#v", expected, got) } } + +func TestValidateOutputErrorWarnings(t *testing.T) { + // TODO: remove this in 0.12 + c := testConfig(t, "output-warnings") + + diags := c.Validate() + if diags.HasErrors() { + t.Fatal("config should not have errors:", diags) + } + if len(diags) != 2 { + t.Fatalf("should have 2 warnings, got %d:\n%s", len(diags), diags) + } + + // this fixture has no explicit count, and should have no warning + c = testConfig(t, "output-no-warnings") + if err := c.Validate(); err != nil { + t.Fatal("config should have no warnings or errors") + } +} diff --git a/config/test-fixtures/output-no-warnings/main.tf b/config/test-fixtures/output-no-warnings/main.tf new file mode 100644 index 0000000000..cd11419a86 --- /dev/null +++ b/config/test-fixtures/output-no-warnings/main.tf @@ -0,0 +1,6 @@ +resource "test_instance" "foo" { +} + +output "foo_id" { + value = "${test_instance.foo.id}" +} diff --git a/config/test-fixtures/output-warnings/main.tf b/config/test-fixtures/output-warnings/main.tf new file mode 100644 index 0000000000..3e335e06cb --- /dev/null +++ b/config/test-fixtures/output-warnings/main.tf @@ -0,0 +1,24 @@ +locals { + "count" = 1 +} + +resource "test_instance" "foo" { + count = "${local.count}" +} + +output "foo_id" { + value = "${test_instance.foo.id}" +} + +variable "condition" { + default = "true" +} + +resource "test_instance" "bar" { + count = "${var.condition ? 1 : 0}" +} + + +output "bar_id" { + value = "${test_instance.bar.id}" +}