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