From 31f6b7474d45b07d3cdb7da91ec2d6119f6f9573 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 9 Feb 2015 09:54:56 -0800 Subject: [PATCH] terraform: more tests --- terraform/context_test.go | 94 ++++++++++++++++----------------- terraform/graph_walk_context.go | 2 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index 285d1cc0c..f995785de 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -378,6 +378,53 @@ func TestContext2Validate_selfRefMultiAll(t *testing.T) { } } +func TestContext2Validate_varRef(t *testing.T) { + m := testModule(t, "validate-variable-ref") + p := testProvider("aws") + c := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + computed := false + p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) { + computed = c.IsComputed("foo") + return nil, nil + } + + c.Validate() + if !computed { + t.Fatal("should be computed") + } +} + +func TestContext2Validate_varRefFilled(t *testing.T) { + m := testModule(t, "validate-variable-ref") + p := testProvider("aws") + c := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "foo": "bar", + }, + }) + + var value interface{} + p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) { + value, _ = c.Get("foo") + return nil, nil + } + + c.Validate() + if value != "bar" { + t.Fatalf("bad: %#v", value) + } +} + /* func TestContextValidate_moduleBadResource(t *testing.T) { m := testModule(t, "validate-module-bad-rc") @@ -519,53 +566,6 @@ func TestContextValidate_provisionerConfig_good(t *testing.T) { } } -func TestContextValidate_varRef(t *testing.T) { - m := testModule(t, "validate-variable-ref") - p := testProvider("aws") - c := testContext(t, &ContextOpts{ - Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, - }) - - computed := false - p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) { - computed = c.IsComputed("foo") - return nil, nil - } - - c.Validate() - if !computed { - t.Fatal("should be computed") - } -} - -func TestContextValidate_varRefFilled(t *testing.T) { - m := testModule(t, "validate-variable-ref") - p := testProvider("aws") - c := testContext(t, &ContextOpts{ - Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, - Variables: map[string]string{ - "foo": "bar", - }, - }) - - var value interface{} - p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) { - value, _ = c.Get("foo") - return nil, nil - } - - c.Validate() - if value != "bar" { - t.Fatalf("bad: %#v", value) - } -} - func TestContextInput(t *testing.T) { input := new(MockUIInput) m := testModule(t, "input-vars") diff --git a/terraform/graph_walk_context.go b/terraform/graph_walk_context.go index e72b23bbf..8f7e2f8f5 100644 --- a/terraform/graph_walk_context.go +++ b/terraform/graph_walk_context.go @@ -41,7 +41,7 @@ func (w *ContextGraphWalker) EnterGraph(g *Graph) EvalContext { Module: w.Context.module, State: w.Context.state, StateLock: &w.Context.stateLock, - Variables: nil, + Variables: w.Context.variables, }, } }