go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/proto/protowalk/processor_output_only_test.go (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package protowalk 16 17 import ( 18 "testing" 19 20 "google.golang.org/protobuf/types/known/structpb" 21 22 . "github.com/smartystreets/goconvey/convey" 23 . "go.chromium.org/luci/common/testing/assertions" 24 ) 25 26 func TestOutputOnly(t *testing.T) { 27 t.Parallel() 28 29 Convey(`Output-only field check`, t, func() { 30 msg := &Outer{ 31 Output: "stuff", 32 OutputInner: &Inner{ 33 Regular: "a bunch of stuff", 34 Output: "ignored because output_inner is cleared", 35 Struct: &structpb.Struct{ 36 Fields: map[string]*structpb.Value{ 37 "input": { 38 Kind: &structpb.Value_StringValue{ 39 StringValue: "inner struct", 40 }, 41 }, 42 }, 43 }, 44 Recursive: &Inner_Recursive{ 45 OutputOnly: 1, 46 Regular: 1, 47 Next: &Inner_Recursive{ 48 OutputOnly: 2, 49 Regular: 2, 50 }, 51 }, 52 }, 53 IntMapInner: map[int32]*Inner{ 54 1: { 55 Recursive: &Inner_Recursive{ 56 OutputOnly: 1, 57 Regular: 1, 58 Next: &Inner_Recursive{ 59 OutputOnly: 2, 60 Regular: 2, 61 Next: &Inner_Recursive{ 62 OutputOnly: 3, 63 Regular: 3, 64 }, 65 }, 66 }, 67 }, 68 }, 69 Struct: &structpb.Struct{ 70 Fields: map[string]*structpb.Value{ 71 "input": { 72 Kind: &structpb.Value_StringValue{ 73 StringValue: "outer struct", 74 }, 75 }, 76 }, 77 }, 78 A: &A{ 79 AValue: "a_value_1", 80 B: &B{ 81 BValue: "b_value_2", 82 A: &A{ 83 AValue: "a_value_3", 84 B: &B{ 85 BValue: "b_value_4", 86 }, 87 }, 88 }, 89 C: &Chh{ 90 AMap: map[string]*A{ 91 "key": { 92 AValue: "a_value_1", 93 B: &B{ 94 BValue: "b_value_2", 95 }, 96 }, 97 }, 98 }, 99 }, 100 B: &B{ 101 BValue: "b_value_1", 102 A: &A{ 103 AValue: "a_value_2", 104 B: &B{ 105 BValue: "b_value_3", 106 A: &A{ 107 AValue: "a_value_4", 108 B: &B{ 109 BValue: "b_value_5", 110 }, 111 }, 112 }, 113 }, 114 }, 115 } 116 So(Fields(msg, &OutputOnlyProcessor{}).Strings(), ShouldResemble, []string{ 117 `.output: cleared OUTPUT_ONLY field`, 118 `.int_map_inner[1].recursive.output_only: cleared OUTPUT_ONLY field`, 119 `.int_map_inner[1].recursive.next.output_only: cleared OUTPUT_ONLY field`, 120 `.int_map_inner[1].recursive.next.next.output_only: cleared OUTPUT_ONLY field`, 121 `.output_inner: cleared OUTPUT_ONLY field`, 122 `.struct: cleared OUTPUT_ONLY field`, 123 `.a.b.b_value: cleared OUTPUT_ONLY field`, 124 `.a.b.a.b.b_value: cleared OUTPUT_ONLY field`, 125 `.a.c.a_map["key"].b.b_value: cleared OUTPUT_ONLY field`, 126 `.b.b_value: cleared OUTPUT_ONLY field`, 127 `.b.a.b.b_value: cleared OUTPUT_ONLY field`, 128 `.b.a.b.a.b.b_value: cleared OUTPUT_ONLY field`, 129 }) 130 131 So(msg, ShouldResembleProto, 132 &Outer{ 133 IntMapInner: map[int32]*Inner{ 134 1: {Recursive: &Inner_Recursive{ 135 Regular: 1, 136 Next: &Inner_Recursive{ 137 Regular: 2, 138 Next: &Inner_Recursive{ 139 Regular: 3, 140 }, 141 }, 142 }}, 143 }, 144 A: &A{ 145 AValue: "a_value_1", 146 B: &B{ 147 A: &A{ 148 AValue: "a_value_3", 149 B: &B{}, 150 }, 151 }, 152 C: &Chh{ 153 AMap: map[string]*A{ 154 "key": { 155 AValue: "a_value_1", 156 B: &B{}, 157 }, 158 }, 159 }, 160 }, 161 B: &B{ 162 A: &A{ 163 AValue: "a_value_2", 164 B: &B{ 165 A: &A{ 166 AValue: "a_value_4", 167 B: &B{}, 168 }, 169 }, 170 }, 171 }, 172 }, 173 ) 174 }) 175 }