pgv_test.cc
Go to the documentation of this file.
1 // NOLINT(namespace-envoy)
2 #include <cstdlib>
3 #include <iostream>
4 
5 // We don't use all the headers in the test below, but including them anyway as
6 // a cheap way to get some C++ compiler sanity checking.
7 #include "envoy/config/cluster/v3/cluster.pb.validate.h"
8 #include "envoy/config/endpoint/v3/endpoint.pb.validate.h"
9 #include "envoy/config/listener/v3/listener.pb.validate.h"
10 #include "envoy/config/route/v3/route.pb.validate.h"
11 #include "envoy/config/core/v3/protocol.pb.validate.h"
12 #include "envoy/config/accesslog/v3/accesslog.pb.validate.h"
13 #include "envoy/extensions/compression/gzip/decompressor/v3/gzip.pb.validate.h"
14 #include "envoy/extensions/filters/http/buffer/v3/buffer.pb.validate.h"
15 #include "envoy/extensions/filters/http/fault/v3/fault.pb.validate.h"
16 #include "envoy/extensions/filters/http/grpc_json_transcoder/v3/transcoder.pb.validate.h"
17 #include "envoy/extensions/filters/http/header_to_metadata/v3/header_to_metadata.pb.validate.h"
18 #include "envoy/extensions/filters/http/health_check/v3/health_check.pb.validate.h"
19 #include "envoy/extensions/filters/http/ip_tagging/v3/ip_tagging.pb.validate.h"
20 #include "envoy/extensions/filters/http/lua/v3/lua.pb.validate.h"
21 #include "envoy/extensions/filters/http/router/v3/router.pb.validate.h"
22 #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.validate.h"
23 #include "envoy/extensions/filters/network/mongo_proxy/v3/mongo_proxy.pb.validate.h"
24 #include "envoy/extensions/filters/network/redis_proxy/v3/redis_proxy.pb.validate.h"
25 #include "envoy/extensions/filters/network/tcp_proxy/v3/tcp_proxy.pb.validate.h"
26 #include "envoy/extensions/health_checkers/redis/v3/redis.pb.validate.h"
27 #include "envoy/config/bootstrap/v3/bootstrap.pb.validate.h"
28 
29 #include "google/protobuf/text_format.h"
30 
31 template <class Proto> struct TestCase {
32  void run() {
34  if (Validate(invalid_message, &err)) {
35  std::cerr << "Unexpected successful validation of invalid message: "
36  << invalid_message.DebugString() << std::endl;
37  exit(EXIT_FAILURE);
38  }
39  if (!Validate(valid_message, &err)) {
40  std::cerr << "Unexpected failed validation of valid message: " << valid_message.DebugString()
41  << ", " << err << std::endl;
42  exit(EXIT_FAILURE);
43  }
44  }
45 
47  Proto& valid_message;
48 };
49 
50 // Basic protoc-gen-validate C++ validation header inclusion and Validate calls
51 // from data plane API.
52 int main(int /*argc*/, char* /*argv*/[]) {
53  envoy::config::bootstrap::v3::Bootstrap invalid_bootstrap;
54  invalid_bootstrap.mutable_static_resources()->add_clusters();
55  // This is a baseline test of the validation features we care about. It's
56  // probably not worth adding in every filter and field that we want to valid
57  // in the API upfront, but as regressions occur, this is the place to add the
58  // specific case.
59  const std::string valid_bootstrap_text = R"EOF(
60  node {}
61  cluster_manager {}
62  admin {
63  access_log_path: "/dev/null"
64  address { pipe { path: "/" } }
65  }
66  )EOF";
67  envoy::config::bootstrap::v3::Bootstrap valid_bootstrap;
68  if (!google::protobuf::TextFormat::ParseFromString(valid_bootstrap_text, &valid_bootstrap)) {
69  std::cerr << "Unable to parse text proto: " << valid_bootstrap_text << std::endl;
70  exit(EXIT_FAILURE);
71  }
72  TestCase<envoy::config::bootstrap::v3::Bootstrap>{invalid_bootstrap, valid_bootstrap}.run();
73 
74  exit(EXIT_SUCCESS);
75 }
TestCase::run
void run()
Definition: pgv_test.cc:32
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error_ref_leak.err
err
Definition: error_ref_leak.py:35
google::protobuf::TextFormat::ParseFromString
static bool ParseFromString(const std::string &input, Message *output)
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.cc:1485
main
int main(int, char *[])
Definition: pgv_test.cc:52
TestCase
Definition: benchmark/test/output_test.h:31
TestCase::invalid_message
Proto & invalid_message
Definition: pgv_test.cc:46
TestCase::valid_message
Proto & valid_message
Definition: pgv_test.cc:47


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:42