2018-08-22 16:59:46 +08:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
|
|
|
#include "communication/bolt/client.hpp"
|
|
|
|
#include "io/network/endpoint.hpp"
|
|
|
|
#include "io/network/utils.hpp"
|
|
|
|
|
|
|
|
DEFINE_string(address, "127.0.0.1", "Server address");
|
|
|
|
DEFINE_int32(port, 7687, "Server port");
|
|
|
|
DEFINE_string(username, "", "Username for the database");
|
|
|
|
DEFINE_string(password, "", "Password for the database");
|
|
|
|
DEFINE_bool(use_ssl, false, "Set to true to connect with SSL to the server.");
|
|
|
|
|
|
|
|
DEFINE_bool(check_failure, false, "Set to true to enable failure checking.");
|
|
|
|
DEFINE_bool(should_fail, false, "Set to true to expect a failure.");
|
|
|
|
DEFINE_string(failure_message, "", "Set to the expected failure message.");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes queries passed as positional arguments and verifies whether they
|
|
|
|
* succeeded, failed, failed with a specific error message or executed without a
|
|
|
|
* specific error occurring.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2020-10-20 18:55:13 +08:00
|
|
|
communication::SSLInit sslInit;
|
2018-08-22 16:59:46 +08:00
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
io::network::Endpoint endpoint(io::network::ResolveHostname(FLAGS_address), FLAGS_port);
|
2018-08-22 16:59:46 +08:00
|
|
|
|
|
|
|
communication::ClientContext context(FLAGS_use_ssl);
|
|
|
|
communication::bolt::Client client(&context);
|
|
|
|
|
2018-10-19 18:28:38 +08:00
|
|
|
client.Connect(endpoint, FLAGS_username, FLAGS_password);
|
2018-08-22 16:59:46 +08:00
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
std::string query(argv[i]);
|
|
|
|
try {
|
|
|
|
client.Execute(query, {});
|
|
|
|
} catch (const communication::bolt::ClientQueryException &e) {
|
|
|
|
if (!FLAGS_check_failure) {
|
2021-02-18 22:32:43 +08:00
|
|
|
if (!FLAGS_failure_message.empty() && e.what() == FLAGS_failure_message) {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL(
|
|
|
|
"The query should have succeeded or failed with an error "
|
|
|
|
"message that isn't equal to '{}' but it failed with that error "
|
|
|
|
"message",
|
|
|
|
FLAGS_failure_message);
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (FLAGS_should_fail) {
|
2021-02-18 22:32:43 +08:00
|
|
|
if (!FLAGS_failure_message.empty() && e.what() != FLAGS_failure_message) {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL(
|
|
|
|
"The query should have failed with an error message of '{}'' but "
|
|
|
|
"instead it failed with '{}'",
|
|
|
|
FLAGS_failure_message, e.what());
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL(
|
|
|
|
"The query shoudn't have failed but it failed with an "
|
|
|
|
"error message '{}'",
|
|
|
|
e.what());
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!FLAGS_check_failure) continue;
|
|
|
|
if (FLAGS_should_fail) {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL(
|
|
|
|
"The query should have failed but instead it executed "
|
|
|
|
"successfully!");
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|