go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luciexe/legacy/annotee/proto/util_test.go (about) 1 // Copyright 2018 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 annopb 16 17 import ( 18 "testing" 19 20 "github.com/golang/protobuf/proto" 21 "google.golang.org/protobuf/encoding/protojson" 22 "google.golang.org/protobuf/types/known/structpb" 23 24 . "github.com/smartystreets/goconvey/convey" 25 26 . "go.chromium.org/luci/common/testing/assertions" 27 ) 28 29 func TestExtractProperties(t *testing.T) { 30 t.Parallel() 31 32 Convey("ExtractProperties", t, func() { 33 root := &Step{} 34 err := proto.UnmarshalText(` 35 substep { 36 step { 37 property { 38 name: "a" 39 value: "1" 40 } 41 property { 42 name: "b" 43 value: "\"str\"" 44 } 45 } 46 } 47 substep { 48 step { 49 property { 50 name: "a" 51 value: "2" 52 } 53 property { 54 name: "c" 55 value: "[1]" 56 } 57 } 58 }`, root) 59 So(err, ShouldBeNil) 60 61 expected := &structpb.Struct{} 62 err = protojson.Unmarshal([]byte(` 63 { 64 "a": 2, 65 "b": "str", 66 "c": [1] 67 }`), expected) 68 So(err, ShouldBeNil) 69 70 actual, err := ExtractProperties(root) 71 So(err, ShouldBeNil) 72 So(actual, ShouldResembleProto, expected) 73 }) 74 }