From c2df70e499c01ad20c745bc60f39a588cad086bb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 3 Feb 2015 19:19:18 -0500 Subject: [PATCH] terraform: complete more nodes --- terraform/eval_provider.go | 4 ++- terraform/eval_provider_test.go | 44 +++++++++++++++++++++++++++++++++ terraform/resource_test.go | 10 ++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/terraform/eval_provider.go b/terraform/eval_provider.go index 032515da6..400308e7f 100644 --- a/terraform/eval_provider.go +++ b/terraform/eval_provider.go @@ -18,7 +18,9 @@ func (n *EvalConfigProvider) Args() ([]EvalNode, []EvalType) { func (n *EvalConfigProvider) Eval( ctx EvalContext, args []interface{}) (interface{}, error) { - return nil, nil + provider := args[0].(ResourceProvider) + config := args[1].(*ResourceConfig) + return nil, provider.Configure(config) } func (n *EvalConfigProvider) Type() EvalType { diff --git a/terraform/eval_provider_test.go b/terraform/eval_provider_test.go index ba56dc22d..456d0fcc4 100644 --- a/terraform/eval_provider_test.go +++ b/terraform/eval_provider_test.go @@ -1,9 +1,53 @@ package terraform import ( + "reflect" "testing" ) +func TestEvalConfigProvider_impl(t *testing.T) { + var _ EvalNode = new(EvalConfigProvider) +} + +func TestEvalConfigProvider(t *testing.T) { + config := testResourceConfig(t, map[string]interface{}{}) + provider := &MockResourceProvider{} + n := &EvalConfigProvider{} + + ctx := &MockEvalContext{ProviderProvider: provider} + args := []interface{}{provider, config} + if actual, err := n.Eval(ctx, args); err != nil { + t.Fatalf("err: %s", err) + } else if actual != nil { + t.Fatalf("bad: %#v", actual) + } + + if !provider.ConfigureCalled { + t.Fatal("should be called") + } + if !reflect.DeepEqual(provider.ConfigureConfig, config) { + t.Fatalf("bad: %#v", provider.ConfigureConfig) + } +} + +func TestEvalConfigProvider_args(t *testing.T) { + config := testResourceConfig(t, map[string]interface{}{}) + provider := &MockResourceProvider{} + providerNode := &EvalLiteral{Value: provider} + configNode := &EvalLiteral{Value: config} + n := &EvalConfigProvider{Provider: providerNode, Config: configNode} + + args, types := n.Args() + expectedArgs := []EvalNode{providerNode, configNode} + expectedTypes := []EvalType{EvalTypeResourceProvider, EvalTypeConfig} + if !reflect.DeepEqual(args, expectedArgs) { + t.Fatalf("bad: %#v", args) + } + if !reflect.DeepEqual(types, expectedTypes) { + t.Fatalf("bad: %#v", args) + } +} + func TestEvalInitProvider_impl(t *testing.T) { var _ EvalNode = new(EvalInitProvider) } diff --git a/terraform/resource_test.go b/terraform/resource_test.go index cc260ec3f..5d9b09a40 100644 --- a/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -116,3 +116,13 @@ func TestResourceConfigGet(t *testing.T) { } } } + +func testResourceConfig( + t *testing.T, c map[string]interface{}) *ResourceConfig { + raw, err := config.NewRawConfig(c) + if err != nil { + t.Fatalf("err: %s", err) + } + + return NewResourceConfig(raw) +}