terraform: all eval nodes tested
This commit is contained in:
parent
c2df70e499
commit
3f0eb528de
|
@ -1,5 +1,9 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
|
||||
// EvalContext is the interface that is given to eval nodes to execute.
|
||||
type EvalContext interface {
|
||||
// InitProvider initializes the provider with the given name and
|
||||
|
@ -9,6 +13,10 @@ type EvalContext interface {
|
|||
// Provider gets the provider instance with the given name (already
|
||||
// initialized) or returns nil if the provider isn't initialized.
|
||||
Provider(string) ResourceProvider
|
||||
|
||||
// Interpolate takes the given raw configuration and completes
|
||||
// the interpolations, returning the processed ResourceConfig.
|
||||
Interpolate(*config.RawConfig) (*ResourceConfig, error)
|
||||
}
|
||||
|
||||
// EvalNode is the interface that must be implemented by graph nodes to
|
||||
|
@ -45,6 +53,11 @@ type MockEvalContext struct {
|
|||
ProviderCalled bool
|
||||
ProviderName string
|
||||
ProviderProvider ResourceProvider
|
||||
|
||||
InterpolateCalled bool
|
||||
InterpolateConfig *config.RawConfig
|
||||
InterpolateConfigResult *ResourceConfig
|
||||
InterpolateError error
|
||||
}
|
||||
|
||||
func (c *MockEvalContext) InitProvider(n string) (ResourceProvider, error) {
|
||||
|
@ -58,3 +71,10 @@ func (c *MockEvalContext) Provider(n string) ResourceProvider {
|
|||
c.ProviderName = n
|
||||
return c.ProviderProvider
|
||||
}
|
||||
|
||||
func (c *MockEvalContext) Interpolate(
|
||||
config *config.RawConfig) (*ResourceConfig, error) {
|
||||
c.InterpolateCalled = true
|
||||
c.InterpolateConfig = config
|
||||
return c.InterpolateConfigResult, c.InterpolateError
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func (n *EvalInterpolate) Args() ([]EvalNode, []EvalType) {
|
|||
|
||||
func (n *EvalInterpolate) Eval(
|
||||
ctx EvalContext, args []interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
return ctx.Interpolate(n.Config)
|
||||
}
|
||||
|
||||
func (n *EvalInterpolate) Type() EvalType {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
|
||||
func TestEvalInterpolate_impl(t *testing.T) {
|
||||
var _ EvalNode = new(EvalInterpolate)
|
||||
}
|
||||
|
||||
func TestEvalInterpolate(t *testing.T) {
|
||||
config, err := config.NewRawConfig(map[string]interface{}{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
n := &EvalInterpolate{Config: config}
|
||||
result := testResourceConfig(t, map[string]interface{}{})
|
||||
ctx := &MockEvalContext{InterpolateConfigResult: result}
|
||||
if actual, err := n.Eval(ctx, nil); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
} else if actual != result {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
|
||||
if !ctx.InterpolateCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if !reflect.DeepEqual(ctx.InterpolateConfig, config) {
|
||||
t.Fatalf("bad: %#v", ctx.InterpolateConfig)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue