terraform/terraform/eval_test.go

41 lines
603 B
Go
Raw Normal View History

package terraform
import (
"testing"
)
func TestMockEvalContext_impl(t *testing.T) {
var _ EvalContext = new(MockEvalContext)
}
2015-02-04 17:30:53 +01:00
func TestEval(t *testing.T) {
2015-02-14 07:58:41 +01:00
var result int
2015-02-04 17:30:53 +01:00
n := &testEvalAdd{
2015-02-14 07:58:41 +01:00
Items: []int{10, 32},
Result: &result,
2015-02-04 17:30:53 +01:00
}
2015-02-14 07:58:41 +01:00
if _, err := Eval(n, nil); err != nil {
2015-02-04 17:30:53 +01:00
t.Fatalf("err: %s", err)
}
if result != 42 {
t.Fatalf("bad: %#v", result)
}
}
type testEvalAdd struct {
2015-02-14 07:58:41 +01:00
Items []int
Result *int
2015-02-04 17:30:53 +01:00
}
2015-02-14 07:58:41 +01:00
func (n *testEvalAdd) Eval(ctx EvalContext) (interface{}, error) {
2015-02-04 17:30:53 +01:00
result := 0
2015-02-14 07:58:41 +01:00
for _, item := range n.Items {
result += item
2015-02-04 17:30:53 +01:00
}
2015-02-14 07:58:41 +01:00
*n.Result = result
return nil, nil
2015-02-04 17:30:53 +01:00
}