Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
test 'require()' works one module-prefix is set
Browse files Browse the repository at this point in the history
* test simple-test.js
* pass down module-prefix to the mock from the tests
  • Loading branch information
weigon committed Jun 14, 2018
1 parent b98597c commit 863a787
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
29 changes: 29 additions & 0 deletions tests/component/test_rest_mock_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,35 @@ TEST_F(RestMockServerTest, metadata_3_secondaries_js) {
ASSERT_NO_THROW(client.execute("select @@port"));
}

/**
* ensure 'simple-client.js' works.
*
* - start the mock-server
* - make a client connect to the mock-server
*/
TEST_F(RestMockServerTest, simple_client_js) {
SCOPED_TRACE("// start mock-server with http-port");

const unsigned server_port = port_pool_.get_next_available();
const unsigned http_port = port_pool_.get_next_available();
const std::string json_stmts = get_data_dir().join("simple-client.js").str();
auto server_mock = launch_mysql_server_mock(json_stmts, server_port, false, http_port);

std::string http_hostname = "127.0.0.1";
std::string http_uri = kMockServerGlobalsRestUri;

EXPECT_TRUE(wait_for_port_ready(server_port, 1000)) << server_mock.get_full_output();

mysqlrouter::MySQLSession client;

SCOPED_TRACE("// connecting via mysql protocol");
ASSERT_NO_THROW(
client.connect("127.0.0.1", server_port, "username", "password", "", ""));

SCOPED_TRACE("// select @@port");
ASSERT_NO_THROW(client.execute("select @@port"));
}



static void init_DIM() {
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers/router_component_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ RouterComponentTest::CommandHandle
RouterComponentTest::launch_mysql_server_mock(const std::string& json_file,
unsigned port,
bool debug_mode,
uint16_t http_port
uint16_t http_port,
const std::string& module_prefix /* = "" */
) const {

if (mysqlserver_mock_exec_.str().empty()) throw std::logic_error("path to mysql-server-mock must not be empty");
return launch_command(mysqlserver_mock_exec_.str(), "--filename=" + json_file
+ " --port=" + std::to_string(port)
+ " --http-port=" + std::to_string(http_port)
+ " --module-prefix=" + (!module_prefix.empty() ? module_prefix : get_data_dir().str())
+ (debug_mode ? " --verbose" : ""),
true);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/router_component_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ class RouterComponentTest {
CommandHandle launch_mysql_server_mock(const std::string& json_file,
unsigned port,
bool debug_mode = true,
uint16_t http_port = 0) const;
uint16_t http_port = 0,
const std::string& module_prefix = "") const;

/** @brief Launches a process.
*
Expand Down

0 comments on commit 863a787

Please sign in to comment.