mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
41 lines
603 B
Go
41 lines
603 B
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMockEvalContext_impl(t *testing.T) {
|
|
var _ EvalContext = new(MockEvalContext)
|
|
}
|
|
|
|
func TestEval(t *testing.T) {
|
|
var result int
|
|
n := &testEvalAdd{
|
|
Items: []int{10, 32},
|
|
Result: &result,
|
|
}
|
|
|
|
if _, err := Eval(n, nil); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if result != 42 {
|
|
t.Fatalf("bad: %#v", result)
|
|
}
|
|
}
|
|
|
|
type testEvalAdd struct {
|
|
Items []int
|
|
Result *int
|
|
}
|
|
|
|
func (n *testEvalAdd) Eval(ctx EvalContext) (interface{}, error) {
|
|
result := 0
|
|
for _, item := range n.Items {
|
|
result += item
|
|
}
|
|
|
|
*n.Result = result
|
|
return nil, nil
|
|
}
|