github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/terraform/eval_context_builtin_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"sync"
     6  	"testing"
     7  )
     8  
     9  func TestBuiltinEvalContextProviderInput(t *testing.T) {
    10  	var lock sync.Mutex
    11  	cache := make(map[string]map[string]interface{})
    12  
    13  	ctx1 := testBuiltinEvalContext(t)
    14  	ctx1.PathValue = []string{"root"}
    15  	ctx1.ProviderInputConfig = cache
    16  	ctx1.ProviderLock = &lock
    17  
    18  	ctx2 := testBuiltinEvalContext(t)
    19  	ctx2.PathValue = []string{"root", "child"}
    20  	ctx2.ProviderInputConfig = cache
    21  	ctx2.ProviderLock = &lock
    22  
    23  	expected1 := map[string]interface{}{"value": "foo"}
    24  	ctx1.SetProviderInput("foo", expected1)
    25  
    26  	expected2 := map[string]interface{}{"value": "bar"}
    27  	ctx2.SetProviderInput("foo", expected2)
    28  
    29  	actual1 := ctx1.ProviderInput("foo")
    30  	actual2 := ctx2.ProviderInput("foo")
    31  
    32  	if !reflect.DeepEqual(actual1, expected1) {
    33  		t.Fatalf("bad: %#v %#v", actual1, expected1)
    34  	}
    35  	if !reflect.DeepEqual(actual2, expected2) {
    36  		t.Fatalf("bad: %#v %#v", actual2, expected2)
    37  	}
    38  }
    39  
    40  func testBuiltinEvalContext(t *testing.T) *BuiltinEvalContext {
    41  	return &BuiltinEvalContext{}
    42  }