From c6474b3e5cce843e384bc2f30d8200ac54721100 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 22 Jul 2014 08:27:16 -0700 Subject: [PATCH] terraform: more test cases --- helper/multierror/error.go | 4 ++++ terraform/context_test.go | 8 ++++++++ terraform/semantics_test.go | 9 +++++++++ terraform/test-fixtures/apply-vars/main.tf | 2 ++ terraform/test-fixtures/smc-uservars/main.tf | 7 +++++++ 5 files changed, 30 insertions(+) diff --git a/helper/multierror/error.go b/helper/multierror/error.go index cddd2fc84..5bfe2b14d 100644 --- a/helper/multierror/error.go +++ b/helper/multierror/error.go @@ -23,6 +23,10 @@ func (e *Error) Error() string { len(e.Errors), strings.Join(points, "\n")) } +func (e *Error) GoString() string { + return fmt.Sprintf("*%#v", *e) +} + // ErrorAppend is a helper function that will append more errors // onto a Error in order to create a larger multi-error. If the // original error is not a Error, it will be turned into one. diff --git a/terraform/context_test.go b/terraform/context_test.go index ec49e5a90..1cf797c7e 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1050,6 +1050,14 @@ func TestContextApply_vars(t *testing.T) { }, }) + w, e := ctx.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + if len(e) > 0 { + t.Fatalf("bad: %s", e) + } + if _, err := ctx.Plan(nil); err != nil { t.Fatalf("err: %s", err) } diff --git a/terraform/semantics_test.go b/terraform/semantics_test.go index 9d7d30ebc..018f448b1 100644 --- a/terraform/semantics_test.go +++ b/terraform/semantics_test.go @@ -18,4 +18,13 @@ func TestSMCUserVariables(t *testing.T) { if len(errs) != 0 { t.Fatalf("err: %#v", errs) } + + // Mapping element override + errs = smcUserVariables(c, map[string]string{ + "foo": "bar", + "map.foo": "baz", + }) + if len(errs) != 0 { + t.Fatalf("err: %#v", errs) + } } diff --git a/terraform/test-fixtures/apply-vars/main.tf b/terraform/test-fixtures/apply-vars/main.tf index e250d0f98..6645e532d 100644 --- a/terraform/test-fixtures/apply-vars/main.tf +++ b/terraform/test-fixtures/apply-vars/main.tf @@ -9,6 +9,8 @@ variable "bar" { default = "baz" } +variable "foo" {} + resource "aws_instance" "foo" { num = "2" bar = "${var.bar}" diff --git a/terraform/test-fixtures/smc-uservars/main.tf b/terraform/test-fixtures/smc-uservars/main.tf index 7e2d10c11..cfa329378 100644 --- a/terraform/test-fixtures/smc-uservars/main.tf +++ b/terraform/test-fixtures/smc-uservars/main.tf @@ -6,3 +6,10 @@ variable "foo" { variable "bar" { default = "baz" } + +# Mapping +variable "map" { + default = { + "foo" = "bar"; + } +}