pgv: bump version to 36e0c0b, validation rules pass C++ compiler checks. (#304)
Also a skeleton for testing valid/invalid Bootstrap (and later other) filters. Signed-off-by: Harvey Tuch <htuch@google.com>pull/306/head
parent
5055a88892
commit
55b98abd2f
5 changed files with 84 additions and 47 deletions
@ -1,33 +1,70 @@ |
|||||||
#include <iostream> |
#include <iostream> |
||||||
#include <cstdlib> |
#include <cstdlib> |
||||||
|
|
||||||
#include "test/validate/test.pb.validate.h" |
// We don't use all the headers in the test below, but including them anyway as
|
||||||
|
// a cheap way to get some C++ compiler sanity checking.
|
||||||
|
#include "api/bootstrap.pb.validate.h" |
||||||
|
#include "api/protocol.pb.validate.h" |
||||||
|
#include "api/cds.pb.validate.h" |
||||||
|
#include "api/eds.pb.validate.h" |
||||||
|
#include "api/lds.pb.validate.h" |
||||||
|
#include "api/rds.pb.validate.h" |
||||||
|
#include "api/rds.pb.validate.h" |
||||||
|
#include "api/filter/accesslog/accesslog.pb.validate.h" |
||||||
|
#include "api/filter/http/buffer.pb.validate.h" |
||||||
|
#include "api/filter/http/fault.pb.validate.h" |
||||||
|
#include "api/filter/http/health_check.pb.validate.h" |
||||||
|
#include "api/filter/http/lua.pb.validate.h" |
||||||
|
#include "api/filter/http/router.pb.validate.h" |
||||||
|
#include "api/filter/http/transcoder.pb.validate.h" |
||||||
|
#include "api/filter/network/http_connection_manager.pb.validate.h" |
||||||
|
#include "api/filter/network/mongo_proxy.pb.validate.h" |
||||||
|
#include "api/filter/network/redis_proxy.pb.validate.h" |
||||||
|
#include "api/filter/network/tcp_proxy.pb.validate.h" |
||||||
|
|
||||||
// Basic protoc-gen-validate C++ validation header inclusion and Validate calls
|
#include "google/protobuf/text_format.h" |
||||||
// from data-plane-api.
|
|
||||||
// TODO(htuch): Switch to using real data-plane-api protos once we can support
|
|
||||||
// the required field types.
|
|
||||||
int main(int argc, char* argv[]) { |
|
||||||
{ |
|
||||||
test::validate::Foo empty; |
|
||||||
|
|
||||||
|
template <class Proto> struct TestCase { |
||||||
|
void run() { |
||||||
std::string err; |
std::string err; |
||||||
if (Validate(empty, &err)) { |
if (Validate(invalid_message, &err)) { |
||||||
std::cout << "Unexpected successful validation of empty proto." << std::endl; |
std::cerr << "Unexpected successful validation of invalid message: " |
||||||
|
<< invalid_message.DebugString() << std::endl; |
||||||
|
exit(EXIT_FAILURE); |
||||||
|
} |
||||||
|
if (!Validate(valid_message, &err)) { |
||||||
|
std::cerr << "Unexpected failed validation of valid message: " << valid_message.DebugString() |
||||||
|
<< ", " << err << std::endl; |
||||||
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
{ |
Proto& invalid_message; |
||||||
test::validate::Foo non_empty; |
Proto& valid_message; |
||||||
non_empty.mutable_baz(); |
}; |
||||||
|
|
||||||
std::string err; |
// Basic protoc-gen-validate C++ validation header inclusion and Validate calls
|
||||||
if (!Validate(non_empty, &err)) { |
// from data-plane-api.
|
||||||
std::cout << "Unexpected failed validation of empty proto: " << err << std::endl; |
int main(int argc, char* argv[]) { |
||||||
exit(EXIT_FAILURE); |
envoy::api::v2::Bootstrap invalid_bootstrap; |
||||||
|
// This is a baseline test of the validation features we care about. It's
|
||||||
|
// probably not worth adding in every filter and field that we want to valid
|
||||||
|
// in the API upfront, but as regressions occur, this is the place to add the
|
||||||
|
// specific case.
|
||||||
|
const std::string valid_bootstrap_text = R"EOF( |
||||||
|
node {} |
||||||
|
cluster_manager {} |
||||||
|
admin { |
||||||
|
access_log_path: "/dev/null" |
||||||
|
address {} |
||||||
} |
} |
||||||
|
)EOF"; |
||||||
|
envoy::api::v2::Bootstrap valid_bootstrap; |
||||||
|
if (!google::protobuf::TextFormat::ParseFromString(valid_bootstrap_text, &valid_bootstrap)) { |
||||||
|
std::cerr << "Unable to parse text proto: " << valid_bootstrap_text << std::endl; |
||||||
|
exit(EXIT_FAILURE); |
||||||
} |
} |
||||||
|
TestCase<envoy::api::v2::Bootstrap>{invalid_bootstrap, valid_bootstrap}.run(); |
||||||
|
|
||||||
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
||||||
} |
} |
||||||
|
@ -1,13 +0,0 @@ |
|||||||
syntax = "proto3"; |
|
||||||
|
|
||||||
package test.validate; |
|
||||||
|
|
||||||
import "validate/validate.proto"; |
|
||||||
|
|
||||||
message Bar { |
|
||||||
uint32 xyz = 1; |
|
||||||
} |
|
||||||
|
|
||||||
message Foo { |
|
||||||
Bar baz = 1 [(.validate.rules).message.required = true]; |
|
||||||
} |
|
Loading…
Reference in new issue