Skip to content

Commit

Permalink
Merge branch 'bump-dependencies' of github.com:becoded/protoc-gen-val…
Browse files Browse the repository at this point in the history
…idate into bump-dependencies

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>
  • Loading branch information
becoded committed Aug 17, 2021
2 parents 115bb5c + 692243f commit 38f0388
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
3 changes: 2 additions & 1 deletion templates/shared/well_known.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const (
)

func FileNeeds(f pgs.File, wk WellKnown) bool {
for _, msg := range f.Messages() {
for _, msg := range f.AllMessages() {
needed := Needs(msg, wk)
if needed {
return true
}
}

return false
}

Expand Down
2 changes: 2 additions & 0 deletions tests/harness/cases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ proto_library(
"subdirectory/in_subdirectory.proto",
"wkt_any.proto",
"wkt_duration.proto",
"wkt_nested.proto",
"wkt_timestamp.proto",
"wkt_wrappers.proto",
],
Expand Down Expand Up @@ -97,6 +98,7 @@ py_proto_library(
"strings.proto",
"wkt_any.proto",
"wkt_duration.proto",
"wkt_nested.proto",
"wkt_timestamp.proto",
"wkt_wrappers.proto",
],
Expand Down
18 changes: 18 additions & 0 deletions tests/harness/cases/wkt_nested.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package tests.harness.cases;
option go_package = "github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/go;cases";

import "validate/validate.proto";

message WktLevelOne {
message WktLevelTwo {
message WktLevelThree {
string uuid = 1 [(validate.rules).string.uuid = true];
}

WktLevelThree three = 1 [(validate.rules).message.required = true];
}

WktLevelTwo two = 1 [(validate.rules).message.required = true];
}
2 changes: 2 additions & 0 deletions tests/harness/cc/diamond_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.validate.h"
2 changes: 2 additions & 0 deletions tests/harness/cc/diamond_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.validate.h"
Expand Down
42 changes: 23 additions & 19 deletions tests/harness/cc/harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_timestamp.pb.validate.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
Expand All @@ -42,6 +44,26 @@

#include "tests/harness/harness.pb.h"

// These macros are defined in the various validation headers and call the
// X macro once for each message class in the header. Add macros here with new
// pb.validate.h headers.
#define X_TESTS_HARNESS_CASES(X) \
X_TESTS_HARNESS_CASES_BOOL(X) \
X_TESTS_HARNESS_CASES_BYTES(X) \
X_TESTS_HARNESS_CASES_ENUMS(X) \
X_TESTS_HARNESS_CASES_FILENAME_WITH_DASH(X) \
X_TESTS_HARNESS_CASES_MAPS(X) \
X_TESTS_HARNESS_CASES_MESSAGES(X) \
X_TESTS_HARNESS_CASES_NUMBERS(X) \
X_TESTS_HARNESS_CASES_ONEOFS(X) \
X_TESTS_HARNESS_CASES_REPEATED(X) \
X_TESTS_HARNESS_CASES_STRINGS(X) \
X_TESTS_HARNESS_CASES_WKT_ANY(X) \
X_TESTS_HARNESS_CASES_WKT_DURATION(X) \
X_TESTS_HARNESS_CASES_WKT_TIMESTAMP(X) \
X_TESTS_HARNESS_CASES_WKT_WRAPPERS(X) \
X_TESTS_HARNESS_CASES_KITCHEN_SINK(X) \

namespace {

using tests::harness::TestCase;
Expand Down Expand Up @@ -107,25 +129,7 @@ std::function<TestResult()> GetValidationCheck(const Any& msg) {
}; \
}

// These macros are defined in the various validation headers and call the
// above macro once for each message class in the header.
X_TESTS_HARNESS_CASES_BOOL(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_BYTES(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_ENUMS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_MAPS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_MESSAGES(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_NUMBERS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_ONEOFS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_REPEATED(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_STRINGS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_WKT_ANY(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_WKT_DURATION(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_WKT_TIMESTAMP(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_WKT_WRAPPERS(TRY_RETURN_VALIDATE_CALLABLE)
X_TESTS_HARNESS_CASES_KITCHEN_SINK(TRY_RETURN_VALIDATE_CALLABLE)
// TODO(akonradi) add macros as the C++ validation code gets fleshed out for
// more field types.

X_TESTS_HARNESS_CASES(TRY_RETURN_VALIDATE_CALLABLE)
#undef TRY_RETURN_VALIDATE_CALLABLE

// TODO(akonradi) remove this once all C++ validation code is done
Expand Down
6 changes: 6 additions & 0 deletions tests/harness/executor/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func init() {
timestampCases,
anyCases,
kitchenSink,
nestedCases,
}

for _, set := range sets {
Expand Down Expand Up @@ -1419,3 +1420,8 @@ var kitchenSink = []TestCase{
{"kitchensink - field - invalid (transitive)", &cases.KitchenSinkMessage{Val: &cases.ComplexTestMsg{Const: "abcd", BoolConst: true, Nested: &cases.ComplexTestMsg{}}}, 14},
{"kitchensink - many - all non-message fields invalid", &cases.KitchenSinkMessage{Val: &cases.ComplexTestMsg{BoolConst: true, FloatVal: &wrapperspb.FloatValue{}, TsVal: &timestamppb.Timestamp{}, FloatConst: 8, AnyVal: &anypb.Any{TypeUrl: "asdf"}, RepTsVal: []*timestamppb.Timestamp{{Nanos: 1}}}}, 13},
}

var nestedCases = []TestCase {
{"nested wkt uuid - field - valid", &cases.WktLevelOne{Two: &cases.WktLevelOne_WktLevelTwo{Three: &cases.WktLevelOne_WktLevelTwo_WktLevelThree{Uuid: "f81d16ef-40e2-40c6-bebc-89aaf5292f9a"}}}, 0},
{"nested wkt uuid - field - invalid", &cases.WktLevelOne{Two: &cases.WktLevelOne_WktLevelTwo{Three: &cases.WktLevelOne_WktLevelTwo_WktLevelThree{Uuid: "not-a-valid-uuid"}}}, 1},
}

0 comments on commit 38f0388

Please sign in to comment.