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-03-25 18:28:52 -05:00
|
|
|
func TestEvalBuildProviderConfig_impl(t *testing.T) {
|
|
|
|
var _ EvalNode = new(EvalBuildProviderConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalBuildProviderConfig(t *testing.T) {
|
|
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
|
|
provider := "foo"
|
|
|
|
|
|
|
|
n := &EvalBuildProviderConfig{
|
|
|
|
Provider: provider,
|
|
|
|
Config: &config,
|
|
|
|
Output: &config,
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := &MockEvalContext{
|
|
|
|
ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
}),
|
|
|
|
ProviderInputConfig: map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
"bar": "baz",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config.Raw, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config.Raw)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalBuildProviderConfig_parentPriority(t *testing.T) {
|
|
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
|
|
provider := "foo"
|
|
|
|
|
|
|
|
n := &EvalBuildProviderConfig{
|
|
|
|
Provider: provider,
|
|
|
|
Config: &config,
|
|
|
|
Output: &config,
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := &MockEvalContext{
|
|
|
|
ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
}),
|
|
|
|
ProviderInputConfig: map[string]interface{}{
|
|
|
|
"foo": "baz",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config.Raw, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config.Raw)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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{}
|
2015-02-14 00:58:41 -06:00
|
|
|
n := &EvalConfigProvider{Config: &config}
|
2015-02-03 18:19:18 -06:00
|
|
|
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
2015-02-14 00:58:41 -06:00
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
2015-02-03 18:19:18 -06:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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}
|
2015-02-14 00:58:41 -06:00
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
2015-02-03 18:06:12 -06:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.InitProviderCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ctx.InitProviderName != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", ctx.InitProviderName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
func TestEvalCloseProvider(t *testing.T) {
|
|
|
|
n := &EvalCloseProvider{Name: "foo"}
|
|
|
|
provider := &MockResourceProvider{}
|
|
|
|
ctx := &MockEvalContext{CloseProviderProvider: provider}
|
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.CloseProviderCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ctx.CloseProviderName != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", ctx.CloseProviderName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:06:12 -06:00
|
|
|
func TestEvalGetProvider_impl(t *testing.T) {
|
|
|
|
var _ EvalNode = new(EvalGetProvider)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvalGetProvider(t *testing.T) {
|
2015-02-14 00:58:41 -06:00
|
|
|
var actual ResourceProvider
|
|
|
|
n := &EvalGetProvider{Name: "foo", Output: &actual}
|
2015-02-03 18:06:12 -06:00
|
|
|
provider := &MockResourceProvider{}
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
2015-02-14 00:58:41 -06:00
|
|
|
if _, err := n.Eval(ctx); err != nil {
|
2015-02-03 18:06:12 -06:00
|
|
|
t.Fatalf("err: %s", err)
|
2015-02-14 00:58:41 -06:00
|
|
|
}
|
|
|
|
if actual != provider {
|
2015-02-03 18:06:12 -06:00
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.ProviderCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ctx.ProviderName != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", ctx.ProviderName)
|
|
|
|
}
|
|
|
|
}
|