opentofu/terraform/eval_provider_test.go
2015-02-19 12:08:32 -08:00

73 lines
1.7 KiB
Go

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{Config: &config}
ctx := &MockEvalContext{ProviderProvider: provider}
if _, err := n.Eval(ctx); err != nil {
t.Fatalf("err: %s", err)
}
if !ctx.ConfigureProviderCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(ctx.ConfigureProviderConfig, config) {
t.Fatalf("bad: %#v", ctx.ConfigureProviderConfig)
}
}
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 _, err := n.Eval(ctx); err != nil {
t.Fatalf("err: %s", err)
}
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) {
var actual ResourceProvider
n := &EvalGetProvider{Name: "foo", Output: &actual}
provider := &MockResourceProvider{}
ctx := &MockEvalContext{ProviderProvider: provider}
if _, err := n.Eval(ctx); err != nil {
t.Fatalf("err: %s", err)
}
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)
}
}