github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/terraform/eval_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMockEvalContext_impl(t *testing.T) {
     8  	var _ EvalContext = new(MockEvalContext)
     9  }
    10  
    11  func TestEval(t *testing.T) {
    12  	var result int
    13  	n := &testEvalAdd{
    14  		Items:  []int{10, 32},
    15  		Result: &result,
    16  	}
    17  
    18  	if _, err := Eval(n, nil); err != nil {
    19  		t.Fatalf("err: %s", err)
    20  	}
    21  
    22  	if result != 42 {
    23  		t.Fatalf("bad: %#v", result)
    24  	}
    25  }
    26  
    27  type testEvalAdd struct {
    28  	Items  []int
    29  	Result *int
    30  }
    31  
    32  func (n *testEvalAdd) Eval(ctx EvalContext) (interface{}, error) {
    33  	result := 0
    34  	for _, item := range n.Items {
    35  		result += item
    36  	}
    37  
    38  	*n.Result = result
    39  	return nil, nil
    40  }