github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/marks_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/muratcelep/terraform/not-internal/lang/marks"
     8  	"github.com/zclconf/go-cty/cty"
     9  )
    10  
    11  func TestMarksEqual(t *testing.T) {
    12  	for i, tc := range []struct {
    13  		a, b  []cty.PathValueMarks
    14  		equal bool
    15  	}{
    16  		{
    17  			[]cty.PathValueMarks{
    18  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    19  			},
    20  			[]cty.PathValueMarks{
    21  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    22  			},
    23  			true,
    24  		},
    25  		{
    26  			[]cty.PathValueMarks{
    27  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    28  			},
    29  			[]cty.PathValueMarks{
    30  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "A"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    31  			},
    32  			false,
    33  		},
    34  		{
    35  			[]cty.PathValueMarks{
    36  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    37  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "b"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    38  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "c"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    39  			},
    40  			[]cty.PathValueMarks{
    41  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "b"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    42  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "c"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    43  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    44  			},
    45  			true,
    46  		},
    47  		{
    48  			[]cty.PathValueMarks{
    49  				cty.PathValueMarks{
    50  					Path:  cty.Path{cty.GetAttrStep{Name: "a"}, cty.GetAttrStep{Name: "b"}},
    51  					Marks: cty.NewValueMarks(marks.Sensitive),
    52  				},
    53  				cty.PathValueMarks{
    54  					Path:  cty.Path{cty.GetAttrStep{Name: "a"}, cty.GetAttrStep{Name: "c"}},
    55  					Marks: cty.NewValueMarks(marks.Sensitive),
    56  				},
    57  			},
    58  			[]cty.PathValueMarks{
    59  				cty.PathValueMarks{
    60  					Path:  cty.Path{cty.GetAttrStep{Name: "a"}, cty.GetAttrStep{Name: "c"}},
    61  					Marks: cty.NewValueMarks(marks.Sensitive),
    62  				},
    63  				cty.PathValueMarks{
    64  					Path:  cty.Path{cty.GetAttrStep{Name: "a"}, cty.GetAttrStep{Name: "b"}},
    65  					Marks: cty.NewValueMarks(marks.Sensitive),
    66  				},
    67  			},
    68  			true,
    69  		},
    70  		{
    71  			[]cty.PathValueMarks{
    72  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    73  			},
    74  			[]cty.PathValueMarks{
    75  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "b"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    76  			},
    77  			false,
    78  		},
    79  		{
    80  			nil,
    81  			nil,
    82  			true,
    83  		},
    84  		{
    85  			[]cty.PathValueMarks{
    86  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    87  			},
    88  			nil,
    89  			false,
    90  		},
    91  		{
    92  			nil,
    93  			[]cty.PathValueMarks{
    94  				cty.PathValueMarks{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(marks.Sensitive)},
    95  			},
    96  			false,
    97  		},
    98  	} {
    99  		t.Run(fmt.Sprint(i), func(t *testing.T) {
   100  			if marksEqual(tc.a, tc.b) != tc.equal {
   101  				t.Fatalf("marksEqual(\n%#v,\n%#v,\n) != %t\n", tc.a, tc.b, tc.equal)
   102  			}
   103  		})
   104  	}
   105  }