2015-02-03 18:06:12 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2015-02-03 18:19:18 -06:00
|
|
|
"reflect"
|
2015-02-03 18:06:12 -06:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-02-03 18:19:18 -06:00
|
|
|
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}
|
2015-02-10 01:32:28 -06:00
|
|
|
args := []interface{}{config}
|
2015-02-03 18:19:18 -06:00
|
|
|
if actual, err := n.Eval(ctx, args); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
} else if actual != nil {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
2015-02-10 01:33:48 -06:00
|
|
|
if !ctx.ConfigureProviderCalled {
|
2015-02-03 18:19:18 -06:00
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
2015-02-10 01:33:48 -06:00
|
|
|
if !reflect.DeepEqual(ctx.ConfigureProviderConfig, config) {
|
|
|
|
t.Fatalf("bad: %#v", ctx.ConfigureProviderConfig)
|
2015-02-03 18:19:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalConfigProvider_args(t *testing.T) {
|
|
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
|
|
configNode := &EvalLiteral{Value: config}
|
2015-02-10 01:32:28 -06:00
|
|
|
n := &EvalConfigProvider{Provider: "foo", Config: configNode}
|
2015-02-03 18:19:18 -06:00
|
|
|
|
|
|
|
args, types := n.Args()
|
2015-02-10 01:32:28 -06:00
|
|
|
expectedArgs := []EvalNode{configNode}
|
|
|
|
expectedTypes := []EvalType{EvalTypeConfig}
|
2015-02-03 18:19:18 -06:00
|
|
|
if !reflect.DeepEqual(args, expectedArgs) {
|
|
|
|
t.Fatalf("bad: %#v", args)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(types, expectedTypes) {
|
|
|
|
t.Fatalf("bad: %#v", args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:06:12 -06:00
|
|
|
func TestEvalInitProvider_impl(t *testing.T) {
|
|
|
|
var _ EvalNode = new(EvalInitProvider)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalInitProvider(t *testing.T) {
|
|
|
|
n := &EvalInitProvider{Name: "foo"}
|
|
|
|
provider := &MockResourceProvider{}
|
|
|
|
ctx := &MockEvalContext{InitProviderProvider: provider}
|
|
|
|
if actual, err := n.Eval(ctx, nil); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
} else if actual != provider {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.InitProviderCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ctx.InitProviderName != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", ctx.InitProviderName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalGetProvider_impl(t *testing.T) {
|
|
|
|
var _ EvalNode = new(EvalGetProvider)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalGetProvider(t *testing.T) {
|
|
|
|
n := &EvalGetProvider{Name: "foo"}
|
|
|
|
provider := &MockResourceProvider{}
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
|
|
if actual, err := n.Eval(ctx, nil); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
} else if actual != provider {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.ProviderCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ctx.ProviderName != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", ctx.ProviderName)
|
|
|
|
}
|
|
|
|
}
|