github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/lang/funcs/redact_test.go (about) 1 package funcs 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/internal/lang/marks" 7 "github.com/zclconf/go-cty/cty" 8 ) 9 10 func TestRedactIfSensitive(t *testing.T) { 11 testCases := map[string]struct { 12 value interface{} 13 marks []cty.ValueMarks 14 want string 15 }{ 16 "sensitive string": { 17 value: "foo", 18 marks: []cty.ValueMarks{cty.NewValueMarks(marks.Sensitive)}, 19 want: "(sensitive value)", 20 }, 21 "marked non-sensitive string": { 22 value: "foo", 23 marks: []cty.ValueMarks{cty.NewValueMarks("boop")}, 24 want: `"foo"`, 25 }, 26 "sensitive string with other marks": { 27 value: "foo", 28 marks: []cty.ValueMarks{cty.NewValueMarks("boop"), cty.NewValueMarks(marks.Sensitive)}, 29 want: "(sensitive value)", 30 }, 31 "sensitive number": { 32 value: 12345, 33 marks: []cty.ValueMarks{cty.NewValueMarks(marks.Sensitive)}, 34 want: "(sensitive value)", 35 }, 36 "non-sensitive number": { 37 value: 12345, 38 marks: []cty.ValueMarks{}, 39 want: "12345", 40 }, 41 } 42 43 for name, tc := range testCases { 44 t.Run(name, func(t *testing.T) { 45 got := redactIfSensitive(tc.value, tc.marks...) 46 if got != tc.want { 47 t.Errorf("wrong result, got %v, want %v", got, tc.want) 48 } 49 }) 50 } 51 }