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

Commit

Permalink
added more tests according to testplan
Browse files Browse the repository at this point in the history
  • Loading branch information
weigon committed Jun 15, 2018
1 parent d0a7d69 commit d82faaa
Show file tree
Hide file tree
Showing 20 changed files with 753 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/http/include/mysqlrouter/http_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HttpServer;
// https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
namespace HttpStatusCode {
using name_type = const char *;
using key_type = int;
using key_type = unsigned int;

constexpr key_type Continue = 100; // RFC 7231
constexpr key_type SwitchingProtocols = 101; // RFC 7231
Expand Down
7 changes: 6 additions & 1 deletion src/mock_server/src/duktape_statement_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,14 @@ struct DuktapeStatementReader::Pimpl {
get_object_integer_value<uint8_t>(-1, "decimals"),
get_object_integer_value<uint32_t>(-1, "length"),
get_object_integer_value<uint16_t>(-1, "character_set", 63),
get_object_integer_value<unsigned>(-1, "repeat", 1)
1 // repeat
};

if (duk_get_prop_string(ctx, -1, "repeat")) {
throw std::runtime_error("repeat is not supported");
}
duk_pop(ctx);

response->columns.push_back(column_info);

duk_pop(ctx); // row
Expand Down
3 changes: 1 addition & 2 deletions tests/component/data/bootstrap_big_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
{
"type": "STRING",
"name": "fake",
"repeat": 4194304 // "Additional field that we use to force generating of big packets"
}
],
"rows": [
Expand All @@ -137,7 +136,7 @@
"default",
"pm",
"localhost:5500",
"x"
"x".repeat(4194304)
],
[
"test",
Expand Down
9 changes: 9 additions & 0 deletions tests/component/data/js_test_nesting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require("path");

// the test-modules are not in the standard paths
//
// the first one should be local_modules/
// test_modules/ is just right next to it
module.paths.push(path.join(module.paths[0], "..", "test_modules"));

require("test-require-nesting-1")
1 change: 1 addition & 0 deletions tests/component/data/js_test_parse_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[
76 changes: 76 additions & 0 deletions tests/component/data/js_test_require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var path = require("path");

// the test-modules are not in the standard paths
//
// the first one should be local_modules/
// test_modules/ is just right next to it
module.paths.push(path.join(module.paths[0], "..", "test_modules"));

var m_direct = require("test-require-direct");
var m_dir_with_indexjs = require("test-require-dir-with-indexjs");
var m_dir_with_packagejson = require("test-require-dir-with-packagejson");
// 'require' the same module again. It shouldn't trigger a reload nor reset the counter
var m_no_reload = require("test-require-direct");

({
stmts: function(stmt) {
// all results share the same column-def
var columns = {
columns: [
{
name: "me",
type: "STRING"
}
]
};

if (stmt === "direct") {
return {
result: Object.assign({
rows: [
[ m_direct.me ]
]
}, columns)
}
} else if (stmt === "dir-with-indexjs") {
return {
result: Object.assign({
rows: [
[ m_dir_with_indexjs.me ]
]
}, columns)
}
} else if (stmt === "dir-with-packagejson") {
return {
result: Object.assign({
rows: [
[ m_dir_with_packagejson.me ]
]
}, columns)
}
} else if (stmt === "no-reload-0") {
return {
result: Object.assign({
rows: [
[ m_direct.counter().toString() ]
]
}, columns)
}
} else if (stmt === "no-reload-1") {
return {
result: Object.assign({
rows: [
[ m_no_reload.counter().toString() ]
]
}, columns)
}
} else {
return {
error: {
code: 1164,
message: "don't know about " + stmt
}
}
}
}
})
17 changes: 17 additions & 0 deletions tests/component/data/js_test_stmts_result_has_infinity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ensure that 'stmts.result.columns[].decimal = Infinity' throws

({
stmts: [
{
result: {
columns: [
{
name: "foo",
type: "STRING",
decimals: Infinity
}
]
}
}
]
})
17 changes: 17 additions & 0 deletions tests/component/data/js_test_stmts_result_has_repeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ensure that 'stmts.result.columns[].repeat' throws

({
stmts: [
{
result: {
columns: [
{
name: "foo",
type: "STRING",
repeat: 25
}
]
}
}
]
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.me = "dir-with-index.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.me = "dir-with-package.json";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "foo.js"
}
6 changes: 6 additions & 0 deletions tests/component/data/test_modules/test-require-direct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var c = 0;

exports.me = "direct";
exports.counter = function() {
return c++;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("test-require-nesting-2")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("test-require-nesting-3")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("test-require-nesting-4")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("test-require-nesting-5")
3 changes: 3 additions & 0 deletions tests/component/data/test_modules/test-require-nesting-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// a parse-error

[
119 changes: 119 additions & 0 deletions tests/component/test_mock_server.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef _WIN32
// ensure windows.h doesn't expose min() nor max()
# define NOMINMAX
#endif

#include <thread>

#include "gmock/gmock.h"
#include "router_component_test.h"

Path g_origin_path;



class MockServerCLITest : public RouterComponentTest, public ::testing::Test {
protected:
void SetUp() override {
set_origin(g_origin_path);
RouterComponentTest::SetUp();
}
};

/**
* ensure mock-server supports --version.
*
* verifies:
*
* - WL12118
* - TS_1-3
*/
TEST_F(MockServerCLITest, has_version) {
auto mysql_server_mock_path = get_mysqlserver_mock_exec().str();

ASSERT_THAT(mysql_server_mock_path, ::testing::StrNe(""));

SCOPED_TRACE("// start binary");
auto cmd = launch_command(mysql_server_mock_path,
std::vector<std::string>{"--version"},
true);

SCOPED_TRACE("// wait for exit");
EXPECT_EQ(cmd.wait_for_exit(1000), 0); // should be quick, and return 0
SCOPED_TRACE("// checking stdout");
EXPECT_THAT(cmd.get_full_output(), ::testing::ContainsRegex("[0-9]\\.[0-9]\\.[0-9]"));
}

/**
* ensure mock-server supports --help.
*/
TEST_F(MockServerCLITest, has_help) {
auto mysql_server_mock_path = get_mysqlserver_mock_exec().str();

ASSERT_THAT(mysql_server_mock_path, ::testing::StrNe(""));

SCOPED_TRACE("// start binary with --help");
auto cmd = launch_command(mysql_server_mock_path,
std::vector<std::string>{"--help"},
true);

SCOPED_TRACE("// wait for exit");
EXPECT_NO_THROW(EXPECT_EQ(cmd.wait_for_exit(1000), 0)); // should be quick, and return 0
SCOPED_TRACE("// checking stdout contains --version");
EXPECT_THAT(cmd.get_full_output(), ::testing::HasSubstr("--version"));
}

/**
* ensure mock-server supports --http-port=65536 fails.
*
* verifies:
*
* - WL12118
* - TS_1-4
*/
TEST_F(MockServerCLITest, http_port_too_large) {
auto mysql_server_mock_path = get_mysqlserver_mock_exec().str();

ASSERT_THAT(mysql_server_mock_path, ::testing::StrNe(""));

SCOPED_TRACE("// start binary with --http-port=65536");
auto cmd = launch_command(mysql_server_mock_path,
std::vector<std::string>{"--http-port=65536"},
true);

SCOPED_TRACE("// wait for exit");
EXPECT_NO_THROW(EXPECT_NE(cmd.wait_for_exit(1000), 0)); // should be quick, and return failure (255)
SCOPED_TRACE("// checking stdout contains errormsg");
EXPECT_THAT(cmd.get_full_output(), ::testing::HasSubstr("was '65536'"));
}


int main(int argc, char *argv[]) {
g_origin_path = Path(argv[0]).dirname();
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading

0 comments on commit d82faaa

Please sign in to comment.