-
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 conformance tests for ignore_empty (#126)
Following #124, this adds conformance tests that ensure the `ignore_empty` rules is consistent with `required`. Mainly, if a field cannot differentiate between unset and the zero value (i.e., is not nullable), then this rule applies; effectively this is just repeated and map fields, as well as non-optional proto3 scalar outside of a oneof. Running against `protovalidate-go`, a few places where `ignore_empty` should be a noop ends up disabling evaluations. This will be a minor follow-up fix in that library. Patches for the other libraries will follow to bring them into conformance with these tests and those in #124.
- Loading branch information
Showing
7 changed files
with
1,627 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto2.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,78 @@ | ||
// 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. | ||
|
||
syntax = "proto2"; | ||
|
||
package buf.validate.conformance.cases; | ||
|
||
import "buf/validate/validate.proto"; | ||
|
||
message IgnoreEmptyProto2ScalarOptional { | ||
optional int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto2ScalarOptionalWithDefault { | ||
optional int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0, | ||
default = 42 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto2ScalarRequired { | ||
required int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto2Message { | ||
optional Msg val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.proto2.message", | ||
message: "foobar", | ||
expression: "this.val == 'foo'", | ||
} | ||
]; | ||
message Msg { | ||
optional string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyProto2Oneof { | ||
oneof o { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
} | ||
|
||
message IgnoreEmptyProto2Repeated { | ||
repeated int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).repeated.min_items = 3 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto2Map { | ||
map<int32, int32> val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).map.min_pairs = 3 | ||
]; | ||
} |
70 changes: 70 additions & 0 deletions
70
proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.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,70 @@ | ||
// 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. | ||
|
||
syntax = "proto3"; | ||
|
||
package buf.validate.conformance.cases; | ||
|
||
import "buf/validate/validate.proto"; | ||
|
||
message IgnoreEmptyProto3Scalar { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto3OptionalScalar { | ||
optional int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto3Message { | ||
optional Msg val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).cel = { | ||
id: "ignore_empty.proto3.message", | ||
message: "foobar", | ||
expression: "this.val == 'foo'", | ||
} | ||
]; | ||
message Msg { | ||
string val = 1; | ||
} | ||
} | ||
|
||
message IgnoreEmptyProto3Oneof { | ||
oneof o { | ||
int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).int32.gt = 0 | ||
]; | ||
} | ||
} | ||
|
||
message IgnoreEmptyProto3Repeated { | ||
repeated int32 val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).repeated.min_items = 3 | ||
]; | ||
} | ||
|
||
message IgnoreEmptyProto3Map { | ||
map<int32, int32> val = 1 [ | ||
(buf.validate.field).ignore_empty = true, | ||
(buf.validate.field).map.min_pairs = 3 | ||
]; | ||
} |
Oops, something went wrong.