-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for Protobuf Editions (#225)
Whew! This one is a doozy. The vast majority of the work is fairly mechanical. In order to test the gauntlet of new semantics that might occur as a result of editions, a new set of test cases are created that mostly mirror the existing tests that already differ between proto2 and proto3. These test cases cover the existing tests that cover edge cases, with the possible set of field presence variants (implicit, explicit, and legacy-required; note that not all of these are valid in all cases) and with both default and expanded repeated field representation. Most of these changes are transparent or invisible even at the `protoreflect` level and mostly just ensure that protovalidate implementations are not tripping up over the wire format or resulting descriptors. One wrinkle is that getting a new enough version of the protobuf toolchain in Bazel for protobuf editions support is tricky; with upstream rules_proto, the latest toolchain you get does not support editions at all. I ran into a couple of very tricky issues getting a newer toolchain to work, but thankfully the resulting changes to work around those issues are relatively simple: - It seems like the `rules_python` repo needs to be defined for protobuf v27+, but the `protobuf_deps` function does not define it. We must define it ourselves. - For unknown reasons, it is necessary to specify both `--proto_compiler` and `--proto_toolchain_for_cc` (and presumably other `--proto_toolchain_for_*` options). The values specified were actually supposedly the default values for these options, so it is unclear why they need to be specified. I suspect this has something to do with refactoring of Bazel's protobuf rules but didn't want to spend more time investigating, as it took a fair bit of time to figure out that it worked in the first place.
- Loading branch information
1 parent
4f56342
commit bb1d618
Showing
44 changed files
with
9,829 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build --experimental_proto_descriptor_sets_include_source_info | ||
build --experimental_proto_descriptor_sets_include_source_info | ||
build --proto_compiler=@com_google_protobuf//:protoc | ||
build --proto_toolchain_for_cc=@com_google_protobuf//:cc_toolchain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto_editions.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright 2023 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
edition = "2023"; | ||
|
||
package buf.validate.conformance.cases; | ||
|
||
import "buf/validate/validate.proto"; | ||
|
||
message IgnoreEmptyEditionsScalarExplicitPresence { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsScalarExplicitPresenceWithDefault { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0, | ||
default = 42 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsScalarImplicitPresence { | ||
int32 val = 1 [ | ||
features.field_presence = IMPLICIT, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsScalarLegacyRequired { | ||
int32 val = 1 [ | ||
features.field_presence = LEGACY_REQUIRED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsScalarLegacyRequiredWithDefault { | ||
int32 val = 1 [ | ||
features.field_presence = LEGACY_REQUIRED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0, | ||
default = 42 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsMessageExplicitPresence { | ||
Msg val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.editions.message" | ||
message: "foobar" | ||
expression: "this.val == 'foo'" | ||
} | ||
]; | ||
message Msg { | ||
string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyEditionsMessageExplicitPresenceDelimited { | ||
Msg val = 1 [ | ||
features.message_encoding = DELIMITED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.editions.message" | ||
message: "foobar" | ||
expression: "this.val == 'foo'" | ||
} | ||
]; | ||
message Msg { | ||
string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyEditionsMessageLegacyRequired { | ||
Msg val = 1 [ | ||
features.field_presence = LEGACY_REQUIRED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.editions.message" | ||
message: "foobar" | ||
expression: "this.val == 'foo'" | ||
} | ||
]; | ||
message Msg { | ||
string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyEditionsMessageLegacyRequiredDelimited { | ||
Msg val = 1 [ | ||
features.message_encoding = DELIMITED, | ||
features.field_presence = LEGACY_REQUIRED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.editions.message" | ||
message: "foobar" | ||
expression: "this.val == 'foo'" | ||
} | ||
]; | ||
message Msg { | ||
string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyEditionsOneof { | ||
oneof o { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
} | ||
|
||
message IgnoreEmptyEditionsRepeated { | ||
repeated int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).repeated.min_items = 3 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsRepeatedExpanded { | ||
repeated int32 val = 1 [ | ||
features.repeated_field_encoding = EXPANDED, | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).repeated.min_items = 3 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyEditionsMap { | ||
map<int32, int32> val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).map.min_pairs = 3 | ||
]; | ||
} |
Oops, something went wrong.