Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for Protobuf Editions #225

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .bazelrc
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
23 changes: 22 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ workspace(name = "com_github_bufbuild_protovalidate")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# This is needed due to an unresolved issue with protobuf v27+.
# https:/protocolbuffers/protobuf/issues/17200
http_archive(
name = "rules_python",
sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
strip_prefix = "rules_python-0.24.0",
url = "https:/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
)

# Use a newer protobuf toolchain for editions support.
http_archive(
name = "com_google_protobuf",
sha256 = "e4ff2aeb767da6f4f52485c2e72468960ddfe5262483879ef6ad552e52757a77",
strip_prefix = "protobuf-27.2",
urls = ["https:/protocolbuffers/protobuf/archive/v27.2.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "rules_buf",
sha256 = "523a4e06f0746661e092d083757263a249fedca535bd6dd819a8c50de074731a",
Expand Down Expand Up @@ -54,4 +75,4 @@ gazelle_dependencies()

load("@rules_buf//gazelle/buf:repositories.bzl", "gazelle_buf_dependencies")

gazelle_buf_dependencies()
gazelle_buf_dependencies()
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ managed:
except:
- buf.build/envoyproxy/protoc-gen-validate
plugins:
- plugin: buf.build/protocolbuffers/go:v1.31.0
- plugin: buf.build/protocolbuffers/go:v1.34.2
out: tools/internal/gen
opt: paths=source_relative
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ proto_library(
"filename-with-dash.proto",
"ignore_empty_proto2.proto",
"ignore_empty_proto3.proto",
"ignore_empty_proto_editions.proto",
"ignore_proto2.proto",
"ignore_proto3.proto",
"ignore_proto_editions.proto",
"kitchen_sink.proto",
"maps.proto",
"messages.proto",
Expand All @@ -34,6 +36,7 @@ proto_library(
"repeated.proto",
"required_field_proto2.proto",
"required_field_proto3.proto",
"required_field_proto_editions.proto",
"strings.proto",
"wkt_any.proto",
"wkt_duration.proto",
Expand Down
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
];
}
Loading
Loading