|
| 1 | +// Copyright 2025 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package protodesc |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + |
| 10 | + "google.golang.org/protobuf/proto" |
| 11 | + "google.golang.org/protobuf/reflect/protoreflect" |
| 12 | + "google.golang.org/protobuf/types/descriptorpb" |
| 13 | + "google.golang.org/protobuf/types/dynamicpb" |
| 14 | + "google.golang.org/protobuf/types/gofeaturespb" |
| 15 | +) |
| 16 | + |
| 17 | +func TestGoFeaturesDynamic(t *testing.T) { |
| 18 | + md := (*gofeaturespb.GoFeatures)(nil).ProtoReflect().Descriptor() |
| 19 | + gf := dynamicpb.NewMessage(md) |
| 20 | + opaque := protoreflect.ValueOfEnum(gofeaturespb.GoFeatures_API_OPAQUE.Number()) |
| 21 | + gf.Set(md.Fields().ByName("api_level"), opaque) |
| 22 | + featureSet := &descriptorpb.FeatureSet{} |
| 23 | + dynamicExt := dynamicpb.NewExtensionType(gofeaturespb.E_Go.TypeDescriptor().Descriptor()) |
| 24 | + proto.SetExtension(featureSet, dynamicExt, gf) |
| 25 | + |
| 26 | + fd := &descriptorpb.FileDescriptorProto{ |
| 27 | + Name: proto.String("a.proto"), |
| 28 | + Dependency: []string{ |
| 29 | + "google/protobuf/go_features.proto", |
| 30 | + }, |
| 31 | + Edition: descriptorpb.Edition_EDITION_2023.Enum(), |
| 32 | + Syntax: proto.String("editions"), |
| 33 | + Options: &descriptorpb.FileOptions{ |
| 34 | + Features: featureSet, |
| 35 | + }, |
| 36 | + } |
| 37 | + fds := &descriptorpb.FileDescriptorSet{ |
| 38 | + File: []*descriptorpb.FileDescriptorProto{ |
| 39 | + ToFileDescriptorProto(descriptorpb.File_google_protobuf_descriptor_proto), |
| 40 | + ToFileDescriptorProto(gofeaturespb.File_google_protobuf_go_features_proto), |
| 41 | + fd, |
| 42 | + }, |
| 43 | + } |
| 44 | + if _, err := NewFiles(fds); err != nil { |
| 45 | + t.Fatal(err) |
| 46 | + } |
| 47 | +} |
0 commit comments