kubeform.dev/terraform-backend-sdk@v0.0.0-20220310143633-45f07fe731c5/configs/configschema/marks_test.go (about) 1 package configschema 2 3 import ( 4 "fmt" 5 "testing" 6 7 "kubeform.dev/terraform-backend-sdk/lang/marks" 8 "github.com/zclconf/go-cty/cty" 9 ) 10 11 func TestBlockValueMarks(t *testing.T) { 12 schema := &Block{ 13 Attributes: map[string]*Attribute{ 14 "unsensitive": { 15 Type: cty.String, 16 Optional: true, 17 }, 18 "sensitive": { 19 Type: cty.String, 20 Sensitive: true, 21 }, 22 }, 23 24 BlockTypes: map[string]*NestedBlock{ 25 "list": { 26 Nesting: NestingList, 27 Block: Block{ 28 Attributes: map[string]*Attribute{ 29 "unsensitive": { 30 Type: cty.String, 31 Optional: true, 32 }, 33 "sensitive": { 34 Type: cty.String, 35 Sensitive: true, 36 }, 37 }, 38 }, 39 }, 40 }, 41 } 42 43 for _, tc := range []struct { 44 given cty.Value 45 expect cty.Value 46 }{ 47 { 48 cty.UnknownVal(schema.ImpliedType()), 49 cty.UnknownVal(schema.ImpliedType()), 50 }, 51 { 52 cty.NullVal(schema.ImpliedType()), 53 cty.NullVal(schema.ImpliedType()), 54 }, 55 { 56 cty.ObjectVal(map[string]cty.Value{ 57 "sensitive": cty.UnknownVal(cty.String), 58 "unsensitive": cty.UnknownVal(cty.String), 59 "list": cty.UnknownVal(schema.BlockTypes["list"].ImpliedType()), 60 }), 61 cty.ObjectVal(map[string]cty.Value{ 62 "sensitive": cty.UnknownVal(cty.String).Mark(marks.Sensitive), 63 "unsensitive": cty.UnknownVal(cty.String), 64 "list": cty.UnknownVal(schema.BlockTypes["list"].ImpliedType()), 65 }), 66 }, 67 { 68 cty.ObjectVal(map[string]cty.Value{ 69 "sensitive": cty.NullVal(cty.String), 70 "unsensitive": cty.UnknownVal(cty.String), 71 "list": cty.ListVal([]cty.Value{ 72 cty.ObjectVal(map[string]cty.Value{ 73 "sensitive": cty.UnknownVal(cty.String), 74 "unsensitive": cty.UnknownVal(cty.String), 75 }), 76 cty.ObjectVal(map[string]cty.Value{ 77 "sensitive": cty.NullVal(cty.String), 78 "unsensitive": cty.NullVal(cty.String), 79 }), 80 }), 81 }), 82 cty.ObjectVal(map[string]cty.Value{ 83 "sensitive": cty.NullVal(cty.String).Mark(marks.Sensitive), 84 "unsensitive": cty.UnknownVal(cty.String), 85 "list": cty.ListVal([]cty.Value{ 86 cty.ObjectVal(map[string]cty.Value{ 87 "sensitive": cty.UnknownVal(cty.String).Mark(marks.Sensitive), 88 "unsensitive": cty.UnknownVal(cty.String), 89 }), 90 cty.ObjectVal(map[string]cty.Value{ 91 "sensitive": cty.NullVal(cty.String).Mark(marks.Sensitive), 92 "unsensitive": cty.NullVal(cty.String), 93 }), 94 }), 95 }), 96 }, 97 } { 98 t.Run(fmt.Sprintf("%#v", tc.given), func(t *testing.T) { 99 got := tc.given.MarkWithPaths(schema.ValueMarks(tc.given, nil)) 100 if !got.RawEquals(tc.expect) { 101 t.Fatalf("\nexpected: %#v\ngot: %#v\n", tc.expect, got) 102 } 103 }) 104 } 105 }