github.com/jameswoolfenden/terraform@v0.11.12-beta1/terraform/eval_output_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  )
     7  
     8  func TestEvalWriteMapOutput(t *testing.T) {
     9  	ctx := new(MockEvalContext)
    10  	ctx.StateState = NewState()
    11  	ctx.StateLock = new(sync.RWMutex)
    12  
    13  	cases := []struct {
    14  		name string
    15  		cfg  *ResourceConfig
    16  		err  bool
    17  	}{
    18  		{
    19  			// Eval should recognize a single map in a slice, and collapse it
    20  			// into the map value
    21  			"single-map",
    22  			&ResourceConfig{
    23  				Config: map[string]interface{}{
    24  					"value": []map[string]interface{}{
    25  						map[string]interface{}{"a": "b"},
    26  					},
    27  				},
    28  			},
    29  			false,
    30  		},
    31  		{
    32  			// we can't apply a multi-valued map to a variable, so this should error
    33  			"multi-map",
    34  			&ResourceConfig{
    35  				Config: map[string]interface{}{
    36  					"value": []map[string]interface{}{
    37  						map[string]interface{}{"a": "b"},
    38  						map[string]interface{}{"c": "d"},
    39  					},
    40  				},
    41  			},
    42  			true,
    43  		},
    44  	}
    45  
    46  	for _, tc := range cases {
    47  		evalNode := &EvalWriteOutput{Name: tc.name}
    48  		ctx.InterpolateConfigResult = tc.cfg
    49  		t.Run(tc.name, func(t *testing.T) {
    50  			_, err := evalNode.Eval(ctx)
    51  			if err != nil && !tc.err {
    52  				t.Fatal(err)
    53  			}
    54  		})
    55  	}
    56  }