github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/eval_diff_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestEvalFilterDiff(t *testing.T) {
     9  	ctx := new(MockEvalContext)
    10  
    11  	cases := []struct {
    12  		Node   *EvalFilterDiff
    13  		Input  *InstanceDiff
    14  		Output *InstanceDiff
    15  	}{
    16  		// With no settings, it returns an empty diff
    17  		{
    18  			&EvalFilterDiff{},
    19  			&InstanceDiff{Destroy: true},
    20  			&InstanceDiff{},
    21  		},
    22  
    23  		// Destroy
    24  		{
    25  			&EvalFilterDiff{Destroy: true},
    26  			&InstanceDiff{Destroy: false},
    27  			&InstanceDiff{Destroy: false},
    28  		},
    29  		{
    30  			&EvalFilterDiff{Destroy: true},
    31  			&InstanceDiff{Destroy: true},
    32  			&InstanceDiff{Destroy: true},
    33  		},
    34  		{
    35  			&EvalFilterDiff{Destroy: true},
    36  			&InstanceDiff{
    37  				Destroy: true,
    38  				Attributes: map[string]*ResourceAttrDiff{
    39  					"foo": &ResourceAttrDiff{},
    40  				},
    41  			},
    42  			&InstanceDiff{Destroy: true},
    43  		},
    44  		{
    45  			&EvalFilterDiff{Destroy: true},
    46  			&InstanceDiff{
    47  				Attributes: map[string]*ResourceAttrDiff{
    48  					"foo": &ResourceAttrDiff{
    49  						RequiresNew: true,
    50  					},
    51  				},
    52  			},
    53  			&InstanceDiff{Destroy: true},
    54  		},
    55  		{
    56  			&EvalFilterDiff{Destroy: true},
    57  			&InstanceDiff{
    58  				Attributes: map[string]*ResourceAttrDiff{
    59  					"foo": &ResourceAttrDiff{},
    60  				},
    61  			},
    62  			&InstanceDiff{Destroy: false},
    63  		},
    64  	}
    65  
    66  	for i, tc := range cases {
    67  		var output *InstanceDiff
    68  		tc.Node.Diff = &tc.Input
    69  		tc.Node.Output = &output
    70  		if _, err := tc.Node.Eval(ctx); err != nil {
    71  			t.Fatalf("err: %s", err)
    72  		}
    73  
    74  		if !reflect.DeepEqual(output, tc.Output) {
    75  			t.Fatalf("bad: %d\n\n%#v", i, output)
    76  		}
    77  	}
    78  }