github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/terraform/eval_interpolate_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/config"
     8  )
     9  
    10  func TestEvalInterpolate_impl(t *testing.T) {
    11  	var _ EvalNode = new(EvalInterpolate)
    12  }
    13  
    14  func TestEvalInterpolate(t *testing.T) {
    15  	config, err := config.NewRawConfig(map[string]interface{}{})
    16  	if err != nil {
    17  		t.Fatalf("err: %s", err)
    18  	}
    19  
    20  	var actual *ResourceConfig
    21  	n := &EvalInterpolate{Config: config, Output: &actual}
    22  	result := testResourceConfig(t, map[string]interface{}{})
    23  	ctx := &MockEvalContext{InterpolateConfigResult: result}
    24  	if _, err := n.Eval(ctx); err != nil {
    25  		t.Fatalf("err: %s", err)
    26  	}
    27  	if actual != result {
    28  		t.Fatalf("bad: %#v", actual)
    29  	}
    30  
    31  	if !ctx.InterpolateCalled {
    32  		t.Fatal("should be called")
    33  	}
    34  	if !reflect.DeepEqual(ctx.InterpolateConfig, config) {
    35  		t.Fatalf("bad: %#v", ctx.InterpolateConfig)
    36  	}
    37  }