MCPcopy Create free account
hub / github.com/bufbuild/buf / TestReparseExtensions

Function TestReparseExtensions

private/pkg/protoencoding/reparse_extensions_test.go:36–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestReparseExtensions(t *testing.T) {
37 t.Parallel()
38
39 descriptorFile := protodesc.ToFileDescriptorProto(descriptorpb.File_google_protobuf_descriptor_proto)
40 durationFile := protodesc.ToFileDescriptorProto(durationpb.File_google_protobuf_duration_proto)
41 timestampFile := protodesc.ToFileDescriptorProto(timestamppb.File_google_protobuf_timestamp_proto)
42 validateFile := protodesc.ToFileDescriptorProto(validate.File_buf_validate_validate_proto)
43
44 // The file will include one custom option with a known/generated type.
45 fieldOpts := &descriptorpb.FieldOptions{}
46 fieldRules := &validate.FieldRules{
47 Required: proto.Bool(true),
48 Type: &validate.FieldRules_Int32{
49 Int32: &validate.Int32Rules{
50 GreaterThan: &validate.Int32Rules_Gt{
51 Gt: 0,
52 },
53 },
54 },
55 }
56 proto.SetExtension(fieldOpts, validate.E_Field, fieldRules)
57 // The file will also contain an unrecognized custom option.
58 const customOptionNum = 54321
59 const customOptionVal = float32(3.14159)
60 var unknownOption []byte
61 unknownOption = protowire.AppendTag(unknownOption, customOptionNum, protowire.Fixed32Type)
62 unknownOption = protowire.AppendFixed32(unknownOption, math.Float32bits(customOptionVal))
63 fieldOpts.ProtoReflect().SetUnknown(unknownOption)
64
65 testFile := &descriptorpb.FileDescriptorProto{
66 Name: proto.String("test.proto"),
67 Syntax: proto.String("proto3"),
68 Package: proto.String("blah.blah"),
69 Dependency: []string{"buf/validate/validate.proto", "google/protobuf/descriptor.proto"},
70 MessageType: []*descriptorpb.DescriptorProto{
71 {
72 Name: proto.String("Foo"),
73 Field: []*descriptorpb.FieldDescriptorProto{
74 {
75 Name: proto.String("bar"),
76 Number: proto.Int32(1),
77 Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
78 Type: descriptorpb.FieldDescriptorProto_TYPE_INT32.Enum(),
79 JsonName: proto.String("bar"),
80 Options: fieldOpts,
81 },
82 },
83 },
84 },
85 Extension: []*descriptorpb.FieldDescriptorProto{
86 {
87 Extendee: proto.String(".google.protobuf.FieldOptions"),
88 Name: proto.String("baz"),
89 Number: proto.Int32(customOptionNum),
90 Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
91 Type: descriptorpb.FieldDescriptorProto_TYPE_FLOAT.Enum(),
92 },
93 },

Callers

nothing calls this directly

Calls 13

ProtoReflectMethod · 0.95
NewResolverFunction · 0.85
ReparseExtensionsFunction · 0.85
StringMethod · 0.65
EnumMethod · 0.65
NumberMethod · 0.65
MessageMethod · 0.65
MarshalMethod · 0.65
UnmarshalMethod · 0.65
DiffMethod · 0.65
SetExtensionMethod · 0.45
ProtoReflectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…