protobuf-go/internal/genid/detect_test.go

73 lines
2.4 KiB
Go
Raw Normal View History

// 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 genid_test
import (
"testing"
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/known/anypb"
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
"google.golang.org/protobuf/types/known/apipb"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/sourcecontextpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
"google.golang.org/protobuf/types/known/typepb"
"google.golang.org/protobuf/types/known/wrapperspb"
"google.golang.org/protobuf/types/pluginpb"
)
func TestWhich(t *testing.T) {
tests := []struct {
in protoreflect.FileDescriptor
want genid.ProtoFile
}{
{descriptorpb.File_google_protobuf_descriptor_proto, genid.Unknown_file},
{pluginpb.File_google_protobuf_compiler_plugin_proto, genid.Unknown_file},
{anypb.File_google_protobuf_any_proto, genid.Any_file},
{timestamppb.File_google_protobuf_timestamp_proto, genid.Timestamp_file},
{durationpb.File_google_protobuf_duration_proto, genid.Duration_file},
{wrapperspb.File_google_protobuf_wrappers_proto, genid.Wrappers_file},
{structpb.File_google_protobuf_struct_proto, genid.Struct_file},
{fieldmaskpb.File_google_protobuf_field_mask_proto, genid.FieldMask_file},
{apipb.File_google_protobuf_api_proto, genid.Api_file},
{typepb.File_google_protobuf_type_proto, genid.Type_file},
{sourcecontextpb.File_google_protobuf_source_context_proto, genid.SourceContext_file},
{emptypb.File_google_protobuf_empty_proto, genid.Empty_file},
}
for _, tt := range tests {
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
rangeDescriptors(tt.in, func(d protoreflect.Descriptor) {
got := genid.WhichFile(d.FullName())
if got != tt.want {
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
t.Errorf("Which(%s) = %v, want %v", d.FullName(), got, tt.want)
}
})
}
}
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
func rangeDescriptors(d interface {
Enums() protoreflect.EnumDescriptors
Messages() protoreflect.MessageDescriptors
}, f func(protoreflect.Descriptor)) {
for i := 0; i < d.Enums().Len(); i++ {
ed := d.Enums().Get(i)
f(ed)
}
for i := 0; i < d.Messages().Len(); i++ {
md := d.Messages().Get(i)
if md.IsMapEntry() {
continue
}
all: move well-known types This is step 2 of 6 in a multi-stage migration to move the well-known types from the google.golang.org/genproto module to the google.golang.org/protobuf module. The generated Go packages for field_mask.proto, api.proto, type.proto, and source_context.proto are being moved over to this module alongside all the other well-known types. In order to move these types between two modules, there needs to be a sequence of changes submitted in decently rapid succession. It is impossible to atomically make these changes, so a brief breakage is inevitable. The steps are as follows: Step 1: Submit a change to cloud.google.com/go/internal/gapicgen to avoid generating the well-known types. Otherwise, the tool will undo the changes made in step 3. See https://code-review.googlesource.com/c/gocloud/+/56810 Step 2: Submit a change to google.golang.org/protobuf that adds the generated well-known types being migrated to that module. In order to prevent the situation where a user links in too old a version of the genproto module such that duplicate registration occurs for the well-known types, the registry is specially modified to provide an error message that instructs users to upgrade the genproto module. See https://golang.org/cl/234937 Step 3: Submit a change to google.golang.org/genproto that switches all generated well-known types to be aliases to the ones declared in google.golang.org/protobuf from the previous step. This will cause the genproto module to incur an dependency on an unreleased version of the protobuf module. See https://github.com/googleapis/go-genproto/pull/372 Step 4: Submit a change to google.golang.org/protobuf that adds a weak module depdency on the genproto module at the revision from the previous step. Step 5: Release google.golang.org/protobuf@v1.24.0. Step 6: Submit a change to google.golang.org/genproto that updates the protobuf module dependency to v1.24.0. Change-Id: I36a19049d2240b67a37dfad20e154505aee7c784 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/234937 Reviewed-by: Damien Neil <dneil@google.com>
2020-05-22 07:02:11 +00:00
f(md)
rangeDescriptors(md, f)
}
}