aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/protobuf/reflect/protorange
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2024-01-30 11:20:39 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2024-01-30 12:12:51 +0300
commitbe737fd8956853e06bd2c4f9fcd4a85188f4c172 (patch)
tree5bd76802fac1096dfd90983c7739d50de367a79f /vendor/google.golang.org/protobuf/reflect/protorange
parentfe62880c46b1f2c9fec779b0dc39f8a92ce256a5 (diff)
downloadydb-be737fd8956853e06bd2c4f9fcd4a85188f4c172.tar.gz
Update vendor/github.com/envoyproxy/go-control-plane to 0.12.0
Diffstat (limited to 'vendor/google.golang.org/protobuf/reflect/protorange')
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protorange/example_test.go307
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make5
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protorange/range.go44
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protorange/range_test.go253
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protorange/ya.make10
5 files changed, 25 insertions, 594 deletions
diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go b/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go
deleted file mode 100644
index 90ceec6c2d..0000000000
--- a/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go
+++ /dev/null
@@ -1,307 +0,0 @@
-// Copyright 2020 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package protorange_test
-
-import (
- "fmt"
- "strings"
- "time"
-
- "google.golang.org/protobuf/encoding/protojson"
- "google.golang.org/protobuf/internal/detrand"
- "google.golang.org/protobuf/proto"
- "google.golang.org/protobuf/reflect/protopath"
- "google.golang.org/protobuf/reflect/protorange"
- "google.golang.org/protobuf/reflect/protoreflect"
- "google.golang.org/protobuf/testing/protopack"
- "google.golang.org/protobuf/types/known/anypb"
- "google.golang.org/protobuf/types/known/timestamppb"
-
- newspb "google.golang.org/protobuf/internal/testprotos/news"
-)
-
-func init() {
- detrand.Disable()
-}
-
-func mustMarshal(m proto.Message) []byte {
- b, err := proto.Marshal(m)
- if err != nil {
- panic(err)
- }
- return b
-}
-
-// Range through every message and clear the unknown fields.
-func Example_discardUnknown() {
- // Populate the article with unknown fields.
- m := &newspb.Article{}
- m.ProtoReflect().SetUnknown(protopack.Message{
- protopack.Tag{1000, protopack.BytesType}, protopack.String("Hello, world!"),
- }.Marshal())
- fmt.Println("has unknown fields?", len(m.ProtoReflect().GetUnknown()) > 0)
-
- // Range through the message and clear all unknown fields.
- fmt.Println("clear unknown fields")
- protorange.Range(m.ProtoReflect(), func(proto protopath.Values) error {
- m, ok := proto.Index(-1).Value.Interface().(protoreflect.Message)
- if ok && len(m.GetUnknown()) > 0 {
- m.SetUnknown(nil)
- }
- return nil
- })
- fmt.Println("has unknown fields?", len(m.ProtoReflect().GetUnknown()) > 0)
-
- // Output:
- // has unknown fields? true
- // clear unknown fields
- // has unknown fields? false
-}
-
-// Print the relative paths as Range iterates through a message
-// in a depth-first order.
-func Example_printPaths() {
- m := &newspb.Article{
- Author: "Russ Cox",
- Date: timestamppb.New(time.Date(2019, time.November, 8, 0, 0, 0, 0, time.UTC)),
- Title: "Go Turns 10",
- Content: "Happy birthday, Go! This weekend we celebrate the 10th anniversary of the Go release...",
- Status: newspb.Article_PUBLISHED,
- Tags: []string{"community", "birthday"},
- Attachments: []*anypb.Any{{
- TypeUrl: "google.golang.org.BinaryAttachment",
- Value: mustMarshal(&newspb.BinaryAttachment{
- Name: "gopher-birthday.png",
- Data: []byte("<binary data>"),
- }),
- }},
- }
-
- // Traverse over all reachable values and print the path.
- protorange.Range(m.ProtoReflect(), func(p protopath.Values) error {
- fmt.Println(p.Path[1:])
- return nil
- })
-
- // Output:
- // .author
- // .date
- // .date.seconds
- // .title
- // .content
- // .status
- // .tags
- // .tags[0]
- // .tags[1]
- // .attachments
- // .attachments[0]
- // .attachments[0].(google.golang.org.BinaryAttachment)
- // .attachments[0].(google.golang.org.BinaryAttachment).name
- // .attachments[0].(google.golang.org.BinaryAttachment).data
-}
-
-// Implement a basic text formatter by ranging through all populated values
-// in a message in depth-first order.
-func Example_formatText() {
- m := &newspb.Article{
- Author: "Brad Fitzpatrick",
- Date: timestamppb.New(time.Date(2018, time.February, 16, 0, 0, 0, 0, time.UTC)),
- Title: "Go 1.10 is released",
- Content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10...",
- Status: newspb.Article_PUBLISHED,
- Tags: []string{"go1.10", "release"},
- Attachments: []*anypb.Any{{
- TypeUrl: "google.golang.org.KeyValueAttachment",
- Value: mustMarshal(&newspb.KeyValueAttachment{
- Name: "checksums.txt",
- Data: map[string]string{
- "go1.10.src.tar.gz": "07cbb9d0091b846c6aea40bf5bc0cea7",
- "go1.10.darwin-amd64.pkg": "cbb38bb6ff6ea86279e01745984445bf",
- "go1.10.linux-amd64.tar.gz": "6b3d0e4a5c77352cf4275573817f7566",
- "go1.10.windows-amd64.msi": "57bda02030f58f5d2bf71943e1390123",
- },
- }),
- }},
- }
-
- // Print a message in a humanly readable format.
- var indent []byte
- protorange.Options{
- Stable: true,
- }.Range(m.ProtoReflect(),
- func(p protopath.Values) error {
- // Print the key.
- var fd protoreflect.FieldDescriptor
- last := p.Index(-1)
- beforeLast := p.Index(-2)
- switch last.Step.Kind() {
- case protopath.FieldAccessStep:
- fd = last.Step.FieldDescriptor()
- fmt.Printf("%s%s: ", indent, fd.Name())
- case protopath.ListIndexStep:
- fd = beforeLast.Step.FieldDescriptor() // lists always appear in the context of a repeated field
- fmt.Printf("%s%d: ", indent, last.Step.ListIndex())
- case protopath.MapIndexStep:
- fd = beforeLast.Step.FieldDescriptor() // maps always appear in the context of a repeated field
- fmt.Printf("%s%v: ", indent, last.Step.MapIndex().Interface())
- case protopath.AnyExpandStep:
- fmt.Printf("%s[%v]: ", indent, last.Value.Message().Descriptor().FullName())
- case protopath.UnknownAccessStep:
- fmt.Printf("%s?: ", indent)
- }
-
- // Starting printing the value.
- switch v := last.Value.Interface().(type) {
- case protoreflect.Message:
- fmt.Printf("{\n")
- indent = append(indent, '\t')
- case protoreflect.List:
- fmt.Printf("[\n")
- indent = append(indent, '\t')
- case protoreflect.Map:
- fmt.Printf("{\n")
- indent = append(indent, '\t')
- case protoreflect.EnumNumber:
- var ev protoreflect.EnumValueDescriptor
- if fd != nil {
- ev = fd.Enum().Values().ByNumber(v)
- }
- if ev != nil {
- fmt.Printf("%v\n", ev.Name())
- } else {
- fmt.Printf("%v\n", v)
- }
- case string, []byte:
- fmt.Printf("%q\n", v)
- default:
- fmt.Printf("%v\n", v)
- }
- return nil
- },
- func(p protopath.Values) error {
- // Finish printing the value.
- last := p.Index(-1)
- switch last.Value.Interface().(type) {
- case protoreflect.Message:
- indent = indent[:len(indent)-1]
- fmt.Printf("%s}\n", indent)
- case protoreflect.List:
- indent = indent[:len(indent)-1]
- fmt.Printf("%s]\n", indent)
- case protoreflect.Map:
- indent = indent[:len(indent)-1]
- fmt.Printf("%s}\n", indent)
- }
- return nil
- },
- )
-
- // Output:
- // {
- // author: "Brad Fitzpatrick"
- // date: {
- // seconds: 1518739200
- // }
- // title: "Go 1.10 is released"
- // content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10..."
- // attachments: [
- // 0: {
- // [google.golang.org.KeyValueAttachment]: {
- // name: "checksums.txt"
- // data: {
- // go1.10.darwin-amd64.pkg: "cbb38bb6ff6ea86279e01745984445bf"
- // go1.10.linux-amd64.tar.gz: "6b3d0e4a5c77352cf4275573817f7566"
- // go1.10.src.tar.gz: "07cbb9d0091b846c6aea40bf5bc0cea7"
- // go1.10.windows-amd64.msi: "57bda02030f58f5d2bf71943e1390123"
- // }
- // }
- // }
- // ]
- // tags: [
- // 0: "go1.10"
- // 1: "release"
- // ]
- // status: PUBLISHED
- // }
-}
-
-// Scan all protobuf string values for a sensitive word and replace it with
-// a suitable alternative.
-func Example_sanitizeStrings() {
- m := &newspb.Article{
- Author: "Hermione Granger",
- Date: timestamppb.New(time.Date(1998, time.May, 2, 0, 0, 0, 0, time.UTC)),
- Title: "Harry Potter vanquishes Voldemort once and for all!",
- Content: "In a final duel between Harry Potter and Lord Voldemort earlier this evening...",
- Tags: []string{"HarryPotter", "LordVoldemort"},
- Attachments: []*anypb.Any{{
- TypeUrl: "google.golang.org.KeyValueAttachment",
- Value: mustMarshal(&newspb.KeyValueAttachment{
- Name: "aliases.txt",
- Data: map[string]string{
- "Harry Potter": "The Boy Who Lived",
- "Tom Riddle": "Lord Voldemort",
- },
- }),
- }},
- }
-
- protorange.Range(m.ProtoReflect(), func(p protopath.Values) error {
- const (
- sensitive = "Voldemort"
- alternative = "[He-Who-Must-Not-Be-Named]"
- )
-
- // Check if there is a sensitive word to redact.
- last := p.Index(-1)
- s, ok := last.Value.Interface().(string)
- if !ok || !strings.Contains(s, sensitive) {
- return nil
- }
- s = strings.Replace(s, sensitive, alternative, -1)
-
- // Store the redacted string back into the message.
- beforeLast := p.Index(-2)
- switch last.Step.Kind() {
- case protopath.FieldAccessStep:
- m := beforeLast.Value.Message()
- fd := last.Step.FieldDescriptor()
- m.Set(fd, protoreflect.ValueOfString(s))
- case protopath.ListIndexStep:
- ls := beforeLast.Value.List()
- i := last.Step.ListIndex()
- ls.Set(i, protoreflect.ValueOfString(s))
- case protopath.MapIndexStep:
- ms := beforeLast.Value.Map()
- k := last.Step.MapIndex()
- ms.Set(k, protoreflect.ValueOfString(s))
- }
- return nil
- })
-
- fmt.Println(protojson.Format(m))
-
- // Output:
- // {
- // "author": "Hermione Granger",
- // "date": "1998-05-02T00:00:00Z",
- // "title": "Harry Potter vanquishes [He-Who-Must-Not-Be-Named] once and for all!",
- // "content": "In a final duel between Harry Potter and Lord [He-Who-Must-Not-Be-Named] earlier this evening...",
- // "tags": [
- // "HarryPotter",
- // "Lord[He-Who-Must-Not-Be-Named]"
- // ],
- // "attachments": [
- // {
- // "@type": "google.golang.org.KeyValueAttachment",
- // "name": "aliases.txt",
- // "data": {
- // "Harry Potter": "The Boy Who Lived",
- // "Tom Riddle": "Lord [He-Who-Must-Not-Be-Named]"
- // }
- // }
- // ]
- // }
-}
diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make b/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make
deleted file mode 100644
index 261b6ab9e8..0000000000
--- a/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make
+++ /dev/null
@@ -1,5 +0,0 @@
-GO_TEST_FOR(vendor/google.golang.org/protobuf/reflect/protorange)
-
-LICENSE(BSD-3-Clause)
-
-END()
diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/range.go b/vendor/google.golang.org/protobuf/reflect/protorange/range.go
index 6f4c58bfb7..7a032758b5 100644
--- a/vendor/google.golang.org/protobuf/reflect/protorange/range.go
+++ b/vendor/google.golang.org/protobuf/reflect/protorange/range.go
@@ -30,7 +30,7 @@ var (
// Range performs a depth-first traversal over reachable values in a message.
//
-// See Options.Range for details.
+// See [Options.Range] for details.
func Range(m protoreflect.Message, f func(protopath.Values) error) error {
return Options{}.Range(m, f, nil)
}
@@ -61,33 +61,33 @@ type Options struct {
}
// Range performs a depth-first traversal over reachable values in a message.
-// The first push and the last pop are to push/pop a protopath.Root step.
-// If push or pop return any non-nil error (other than Break or Terminate),
+// The first push and the last pop are to push/pop a [protopath.Root] step.
+// If push or pop return any non-nil error (other than [Break] or [Terminate]),
// it terminates the traversal and is returned by Range.
//
// The rules for traversing a message is as follows:
//
-// • For messages, iterate over every populated known and extension field.
-// Each field is preceded by a push of a protopath.FieldAccess step,
-// followed by recursive application of the rules on the field value,
-// and succeeded by a pop of that step.
-// If the message has unknown fields, then push an protopath.UnknownAccess step
-// followed immediately by pop of that step.
+// - For messages, iterate over every populated known and extension field.
+// Each field is preceded by a push of a [protopath.FieldAccess] step,
+// followed by recursive application of the rules on the field value,
+// and succeeded by a pop of that step.
+// If the message has unknown fields, then push an [protopath.UnknownAccess] step
+// followed immediately by pop of that step.
//
-// • As an exception to the above rule, if the current message is a
-// google.protobuf.Any message, expand the underlying message (if resolvable).
-// The expanded message is preceded by a push of a protopath.AnyExpand step,
-// followed by recursive application of the rules on the underlying message,
-// and succeeded by a pop of that step. Mutations to the expanded message
-// are written back to the Any message when popping back out.
+// - As an exception to the above rule, if the current message is a
+// google.protobuf.Any message, expand the underlying message (if resolvable).
+// The expanded message is preceded by a push of a [protopath.AnyExpand] step,
+// followed by recursive application of the rules on the underlying message,
+// and succeeded by a pop of that step. Mutations to the expanded message
+// are written back to the Any message when popping back out.
//
-// • For lists, iterate over every element. Each element is preceded by a push
-// of a protopath.ListIndex step, followed by recursive application of the rules
-// on the list element, and succeeded by a pop of that step.
+// - For lists, iterate over every element. Each element is preceded by a push
+// of a [protopath.ListIndex] step, followed by recursive application of the rules
+// on the list element, and succeeded by a pop of that step.
//
-// • For maps, iterate over every entry. Each entry is preceded by a push
-// of a protopath.MapIndex step, followed by recursive application of the rules
-// on the map entry value, and succeeded by a pop of that step.
+// - For maps, iterate over every entry. Each entry is preceded by a push
+// of a [protopath.MapIndex] step, followed by recursive application of the rules
+// on the map entry value, and succeeded by a pop of that step.
//
// Mutations should only be made to the last value, otherwise the effects on
// traversal will be undefined. If the mutation is made to the last value
@@ -96,7 +96,7 @@ type Options struct {
// populates a few fields in that message, then the newly modified fields
// will be traversed.
//
-// The protopath.Values provided to push functions is only valid until the
+// The [protopath.Values] provided to push functions is only valid until the
// corresponding pop call and the values provided to a pop call is only valid
// for the duration of the pop call itself.
func (o Options) Range(m protoreflect.Message, push, pop func(protopath.Values) error) error {
diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go b/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go
deleted file mode 100644
index a8ca6a0b62..0000000000
--- a/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go
+++ /dev/null
@@ -1,253 +0,0 @@
-// Copyright 2020 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package protorange
-
-import (
- "testing"
- "time"
-
- "github.com/google/go-cmp/cmp"
- "github.com/google/go-cmp/cmp/cmpopts"
- "google.golang.org/protobuf/proto"
- "google.golang.org/protobuf/reflect/protopath"
- "google.golang.org/protobuf/reflect/protoreflect"
- "google.golang.org/protobuf/reflect/protoregistry"
- "google.golang.org/protobuf/testing/protocmp"
-
- newspb "google.golang.org/protobuf/internal/testprotos/news"
- anypb "google.golang.org/protobuf/types/known/anypb"
- timestamppb "google.golang.org/protobuf/types/known/timestamppb"
-)
-
-func mustMarshal(m proto.Message) []byte {
- b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m)
- if err != nil {
- panic(err)
- }
- return b
-}
-
-var transformReflectValue = cmp.Transformer("", func(v protoreflect.Value) interface{} {
- switch v := v.Interface().(type) {
- case protoreflect.Message:
- return v.Interface()
- case protoreflect.Map:
- ms := map[interface{}]protoreflect.Value{}
- v.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
- ms[k.Interface()] = v
- return true
- })
- return ms
- case protoreflect.List:
- ls := []protoreflect.Value{}
- for i := 0; i < v.Len(); i++ {
- ls = append(ls, v.Get(i))
- }
- return ls
- default:
- return v
- }
-})
-
-func TestRange(t *testing.T) {
- m2 := (&newspb.KeyValueAttachment{
- Name: "checksums.txt",
- Data: map[string]string{
- "go1.10.src.tar.gz": "07cbb9d0091b846c6aea40bf5bc0cea7",
- "go1.10.darwin-amd64.pkg": "cbb38bb6ff6ea86279e01745984445bf",
- "go1.10.linux-amd64.tar.gz": "6b3d0e4a5c77352cf4275573817f7566",
- "go1.10.windows-amd64.msi": "57bda02030f58f5d2bf71943e1390123",
- },
- }).ProtoReflect()
- m := (&newspb.Article{
- Author: "Brad Fitzpatrick",
- Date: timestamppb.New(time.Date(2018, time.February, 16, 0, 0, 0, 0, time.UTC)),
- Title: "Go 1.10 is released",
- Content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10...",
- Status: newspb.Article_PUBLISHED,
- Tags: []string{"go1.10", "release"},
- Attachments: []*anypb.Any{{
- TypeUrl: "google.golang.org.KeyValueAttachment",
- Value: mustMarshal(m2.Interface()),
- }},
- }).ProtoReflect()
-
- // Nil push and pop functions should not panic.
- noop := func(protopath.Values) error { return nil }
- Options{}.Range(m, nil, nil)
- Options{}.Range(m, noop, nil)
- Options{}.Range(m, nil, noop)
-
- getByName := func(m protoreflect.Message, s protoreflect.Name) protoreflect.Value {
- fds := m.Descriptor().Fields()
- return m.Get(fds.ByName(s))
- }
-
- wantPaths := []string{
- ``,
- `.author`,
- `.date`,
- `.date.seconds`,
- `.title`,
- `.content`,
- `.attachments`,
- `.attachments[0]`,
- `.attachments[0].(google.golang.org.KeyValueAttachment)`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).name`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).data`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.darwin-amd64.pkg"]`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.linux-amd64.tar.gz"]`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.src.tar.gz"]`,
- `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.windows-amd64.msi"]`,
- `.tags`,
- `.tags[0]`,
- `.tags[1]`,
- `.status`,
- }
- wantValues := []protoreflect.Value{
- protoreflect.ValueOfMessage(m),
- getByName(m, "author"),
- getByName(m, "date"),
- getByName(getByName(m, "date").Message(), "seconds"),
- getByName(m, `title`),
- getByName(m, `content`),
- getByName(m, `attachments`),
- getByName(m, `attachments`).List().Get(0),
- protoreflect.ValueOfMessage(m2),
- getByName(m2, `name`),
- getByName(m2, `data`),
- getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.darwin-amd64.pkg").MapKey()),
- getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.linux-amd64.tar.gz").MapKey()),
- getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.src.tar.gz").MapKey()),
- getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.windows-amd64.msi").MapKey()),
- getByName(m, `tags`),
- getByName(m, `tags`).List().Get(0),
- getByName(m, `tags`).List().Get(1),
- getByName(m, `status`),
- }
-
- tests := []struct {
- resolver interface {
- protoregistry.ExtensionTypeResolver
- protoregistry.MessageTypeResolver
- }
-
- errorAt int
- breakAt int
- terminateAt int
-
- wantPaths []string
- wantValues []protoreflect.Value
- wantError error
- }{{
- wantPaths: wantPaths,
- wantValues: wantValues,
- }, {
- resolver: (*protoregistry.Types)(nil),
- wantPaths: append(append(wantPaths[:8:8],
- `.attachments[0].type_url`,
- `.attachments[0].value`,
- ), wantPaths[15:]...),
- wantValues: append(append(wantValues[:8:8],
- protoreflect.ValueOfString("google.golang.org.KeyValueAttachment"),
- protoreflect.ValueOfBytes(mustMarshal(m2.Interface())),
- ), wantValues[15:]...),
- }, {
- errorAt: 5, // return error within newspb.Article
- wantPaths: wantPaths[:5],
- wantValues: wantValues[:5],
- wantError: cmpopts.AnyError,
- }, {
- terminateAt: 11, // terminate within newspb.KeyValueAttachment
- wantPaths: wantPaths[:11],
- wantValues: wantValues[:11],
- }, {
- breakAt: 11, // break within newspb.KeyValueAttachment
- wantPaths: append(wantPaths[:11:11], wantPaths[15:]...),
- wantValues: append(wantValues[:11:11], wantValues[15:]...),
- }, {
- errorAt: 17, // return error within newspb.Article.Tags
- wantPaths: wantPaths[:17],
- wantValues: wantValues[:17],
- wantError: cmpopts.AnyError,
- }, {
- breakAt: 17, // break within newspb.Article.Tags
- wantPaths: append(wantPaths[:17:17], wantPaths[18:]...),
- wantValues: append(wantValues[:17:17], wantValues[18:]...),
- }, {
- terminateAt: 17, // terminate within newspb.Article.Tags
- wantPaths: wantPaths[:17],
- wantValues: wantValues[:17],
- }, {
- errorAt: 13, // return error within newspb.KeyValueAttachment.Data
- wantPaths: wantPaths[:13],
- wantValues: wantValues[:13],
- wantError: cmpopts.AnyError,
- }, {
- breakAt: 13, // break within newspb.KeyValueAttachment.Data
- wantPaths: append(wantPaths[:13:13], wantPaths[15:]...),
- wantValues: append(wantValues[:13:13], wantValues[15:]...),
- }, {
- terminateAt: 13, // terminate within newspb.KeyValueAttachment.Data
- wantPaths: wantPaths[:13],
- wantValues: wantValues[:13],
- }}
- for _, tt := range tests {
- t.Run("", func(t *testing.T) {
- var gotPaths []string
- var gotValues []protoreflect.Value
- var stackPaths []string
- var stackValues []protoreflect.Value
- gotError := Options{
- Stable: true,
- Resolver: tt.resolver,
- }.Range(m,
- func(p protopath.Values) error {
- gotPaths = append(gotPaths, p.Path[1:].String())
- stackPaths = append(stackPaths, p.Path[1:].String())
- gotValues = append(gotValues, p.Index(-1).Value)
- stackValues = append(stackValues, p.Index(-1).Value)
- switch {
- case tt.errorAt > 0 && tt.errorAt == len(gotPaths):
- return cmpopts.AnyError
- case tt.breakAt > 0 && tt.breakAt == len(gotPaths):
- return Break
- case tt.terminateAt > 0 && tt.terminateAt == len(gotPaths):
- return Terminate
- default:
- return nil
- }
- },
- func(p protopath.Values) error {
- gotPath := p.Path[1:].String()
- wantPath := stackPaths[len(stackPaths)-1]
- if wantPath != gotPath {
- t.Errorf("%d: pop path mismatch: got %v, want %v", len(gotPaths), gotPath, wantPath)
- }
- gotValue := p.Index(-1).Value
- wantValue := stackValues[len(stackValues)-1]
- if diff := cmp.Diff(wantValue, gotValue, transformReflectValue, protocmp.Transform()); diff != "" {
- t.Errorf("%d: pop value mismatch (-want +got):\n%v", len(gotValues), diff)
- }
- stackPaths = stackPaths[:len(stackPaths)-1]
- stackValues = stackValues[:len(stackValues)-1]
- return nil
- },
- )
- if n := len(stackPaths) + len(stackValues); n > 0 {
- t.Errorf("stack mismatch: got %d unpopped items", n)
- }
- if diff := cmp.Diff(tt.wantPaths, gotPaths); diff != "" {
- t.Errorf("paths mismatch (-want +got):\n%s", diff)
- }
- if diff := cmp.Diff(tt.wantValues, gotValues, transformReflectValue, protocmp.Transform()); diff != "" {
- t.Errorf("values mismatch (-want +got):\n%s", diff)
- }
- if !cmp.Equal(gotError, tt.wantError, cmpopts.EquateErrors()) {
- t.Errorf("error mismatch: got %v, want %v", gotError, tt.wantError)
- }
- })
- }
-}
diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/ya.make b/vendor/google.golang.org/protobuf/reflect/protorange/ya.make
index 29c6345337..fc294f2b0e 100644
--- a/vendor/google.golang.org/protobuf/reflect/protorange/ya.make
+++ b/vendor/google.golang.org/protobuf/reflect/protorange/ya.make
@@ -2,12 +2,8 @@ GO_LIBRARY()
LICENSE(BSD-3-Clause)
-SRCS(range.go)
-
-GO_TEST_SRCS(range_test.go)
-
-GO_XTEST_SRCS(example_test.go)
+SRCS(
+ range.go
+)
END()
-
-RECURSE(gotest)