Skip to content

Commit

Permalink
Add ignore enum conformance tests (#170)
Browse files Browse the repository at this point in the history
Follow up to #137 to add matching (exhaustive) conformance tests.
  • Loading branch information
rodaine authored Feb 16, 2024
1 parent 170c298 commit 8074ae2
Show file tree
Hide file tree
Showing 10 changed files with 7,666 additions and 8 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ test: generate ## Run all unit tests
lint: lint-proto lint-go ## Lint code and protos

.PHONY: lint-go
lint-go: $(BIN)/golangci-lint
lint-go: | $(BIN)/golangci-lint
$(BIN)/golangci-lint run --modules-download-mode=readonly --timeout=3m0s ./tools/...

.PHONY: lint-go-fix
lint-go-fix: $(BIN)/golangci-lint
lint-go-fix: | $(BIN)/golangci-lint
$(BIN)/golangci-lint run --fix --modules-download-mode=readonly --timeout=3m0s ./tools/...

.PHONY: lint-proto
lint-proto: $(BIN)/buf
lint-proto: | $(BIN)/buf
$(BIN)/buf lint
$(BIN)/buf breaking --against '.git#branch=main'

Expand All @@ -51,7 +51,10 @@ conformance: ## Build conformance harness
$(GO) build -o $(BIN)/protovalidate-conformance ./tools/protovalidate-conformance

.PHONY: generate
generate: generate-bazel generate-proto generate-license ## Regenerate code and license headers
generate: ## Regenerate code and license headers
$(MAKE) generate-bazel
$(MAKE) generate-proto
$(MAKE) generate-license

.PHONY: bazel
bazel: generate-bazel
Expand All @@ -62,12 +65,12 @@ generate-bazel:
bazel run //:gazelle

.PHONY: generate-proto
generate-proto: $(BIN)/buf
generate-proto: | $(BIN)/buf
rm -rf tools/internal/gen/*/
$(BIN)/buf generate

.PHONY: generate-license
generate-license: $(BIN)/license-header
generate-license: | $(BIN)/license-header
@# We want to operate on a list of modified and new files, excluding
@# deleted and ignored files. git-ls-files can't do this alone. comm -23 takes
@# two files and prints the union, dropping lines common to both (-3) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ proto_library(
"filename-with-dash.proto",
"ignore_empty_proto2.proto",
"ignore_empty_proto3.proto",
"ignore_proto2.proto",
"ignore_proto3.proto",
"kitchen_sink.proto",
"maps.proto",
"messages.proto",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
// 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 Proto2ScalarOptionalIgnoreUnspecified {
optional int32 val = 1 [(buf.validate.field).int32.gt = 0];
}

message Proto2ScalarOptionalIgnoreUnspecifiedWithDefault {
optional int32 val = 1 [
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarOptionalIgnoreEmpty {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarOptionalIgnoreEmptyWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarOptionalIgnoreDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarOptionalIgnoreDefaultWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarRequiredIgnoreUnspecified {
required int32 val = 1 [(buf.validate.field).int32.gt = 0];
}

message Proto2ScalarRequiredIgnoreUnspecifiedWithDefault {
required int32 val = 1 [
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarRequiredIgnoreEmpty {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarRequiredIgnoreEmptyWithDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarRequiredIgnoreDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarRequiredIgnoreDefaultWithDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2MessageOptionalIgnoreUnspecified {
optional Msg val = 1 [(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}];
message Msg {
optional string val = 1;
}
}

message Proto2MessageOptionalIgnoreEmpty {
optional Msg val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
optional string val = 1;
}
}

message Proto2MessageOptionalIgnoreDefault {
optional Msg val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
optional string val = 1;
}
}

message Proto2MessageRequiredIgnoreUnspecified {
required Msg val = 1 [(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}];
message Msg {
optional string val = 1;
}
}

message Proto2MessageRequiredIgnoreEmpty {
required Msg val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
optional string val = 1;
}
}

message Proto2MessageRequiredIgnoreDefault {
required Msg val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
expression: "this.val == 'foo'",
}
];
message Msg {
optional string val = 1;
}
}

message Proto2OneofIgnoreUnspecified {
oneof o {
int32 val = 1 [(buf.validate.field).int32.gt = 0];
}
}

message Proto2OneofIgnoreUnspecifiedWithDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).int32.gt = 0,
default = -42
];
}
}

message Proto2OneofIgnoreEmpty {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0
];
}
}

message Proto2OneofIgnoreEmptyWithDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).int32.gt = 0,
default = -42
];
}
}

message Proto2OneofIgnoreDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0
];
}
}

message Proto2OneofIgnoreDefaultWithDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).int32.gt = 0,
default = -42
];
}
}

message Proto2RepeatedIgnoreUnspecified {
repeated int32 val = 1 [(buf.validate.field).repeated.min_items = 3];
}

message Proto2RepeatedIgnoreEmpty {
repeated int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).repeated.min_items = 3
];
}

message Proto2RepeatedIgnoreDefault {
repeated int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).repeated.min_items = 3
];
}

message Proto2MapIgnoreUnspecified {
map<int32, int32> val = 1 [(buf.validate.field).map.min_pairs = 3];
}

message Proto2MapIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).map.min_pairs = 3
];
}

message Proto2MapIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).map.min_pairs = 3
];
}

message Proto2RepeatedItemIgnoreUnspecified {
repeated int32 val = 1 [(buf.validate.field).repeated.items.int32.gt = 0];
}

message Proto2RepeatedItemIgnoreEmpty {
repeated int32 val = 1 [
(buf.validate.field).repeated.items.ignore = IGNORE_EMPTY,
(buf.validate.field).repeated.items.int32.gt = 0
];
}

message Proto2RepeatedItemIgnoreDefault {
repeated int32 val = 1 [
(buf.validate.field).repeated.items.ignore = IGNORE_DEFAULT,
(buf.validate.field).repeated.items.int32.gt = 0
];
}

message Proto2MapKeyIgnoreUnspecified {
map<int32, int32> val = 1 [(buf.validate.field).map.keys.int32.gt = 0];
}

message Proto2MapKeyIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).map.keys.ignore = IGNORE_EMPTY,
(buf.validate.field).map.keys.int32.gt = 0
];
}

message Proto2MapKeyIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).map.keys.ignore = IGNORE_DEFAULT,
(buf.validate.field).map.keys.int32.gt = 0
];
}

message Proto2MapValueIgnoreUnspecified {
map<int32, int32> val = 1 [(buf.validate.field).map.values.int32.gt = 0];
}

message Proto2MapValueIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).map.values.ignore = IGNORE_EMPTY,
(buf.validate.field).map.values.int32.gt = 0
];
}

message Proto2MapValueIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).map.values.ignore = IGNORE_DEFAULT,
(buf.validate.field).map.values.int32.gt = 0
];
}
Loading

0 comments on commit 8074ae2

Please sign in to comment.