Skip to content

Commit a133b50

Browse files
authored
Merge pull request #321 from Enmk/better_cloumn_name_test
Better tests for #317
2 parents f04d913 + e5b33f2 commit a133b50

File tree

2 files changed

+49
-62
lines changed

2 files changed

+49
-62
lines changed

ut/abnormal_column_names_test.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,64 @@
1-
#include "abnormal_column_names_test.h"
2-
#include "utils.h"
31

42
#include <clickhouse/columns/column.h>
53
#include <clickhouse/block.h>
4+
5+
#include "utils.h"
6+
7+
#include <gtest/gtest.h>
8+
69
#include <unordered_set>
710
#include <iostream>
811

912
namespace {
10-
using namespace clickhouse;
11-
}
13+
using namespace clickhouse;
1214

13-
void AbnormalColumnNamesClientTest::SetUp() {
14-
client_ = std::make_unique<Client>(std::get<0>(GetParam()));
15-
}
15+
std::string getColumnNames(const Block& block) {
16+
std::string result;
17+
for (size_t i = 0; i < block.GetColumnCount(); ++i) {
18+
result += block.GetColumnName(i);
19+
if (i != block.GetColumnCount() - 1)
20+
result += ',';
21+
}
1622

17-
void AbnormalColumnNamesClientTest::TearDown() {
18-
client_.reset();
23+
return result;
1924
}
25+
}
26+
27+
struct AbnormalColumnNamesClientTestCase {
28+
ClientOptions client_options;
29+
std::vector<std::string> queries;
30+
std::vector<std::string> expected_names;
31+
};
32+
33+
class AbnormalColumnNamesClientTest : public testing::TestWithParam<AbnormalColumnNamesClientTestCase> {
34+
protected:
35+
void SetUp() override {
36+
client_ = std::make_unique<Client>(GetParam().client_options);
37+
}
38+
void TearDown() override {
39+
client_.reset();
40+
}
41+
42+
std::unique_ptr<clickhouse::Client> client_;
43+
};
44+
2045

21-
// Sometimes gtest fails to detect that this test is instantiated elsewhere, suppress the error explicitly.
22-
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AbnormalColumnNamesClientTest);
2346
TEST_P(AbnormalColumnNamesClientTest, Select) {
24-
// TODO(vnemkov): move expected results into the test parameters, also get rid of PrettyPrintBlock
25-
static const std::vector<std::string> expect_results {
26-
"+-------+-------+-------+\n"\
27-
"| 123 | 231 | 113 |\n"\
28-
"+-------+-------+-------+\n"\
29-
"| UInt8 | UInt8 | UInt8 |\n"\
30-
"+-------+-------+-------+\n"\
31-
"| 123 | 231 | 113 |\n"\
32-
"+-------+-------+-------+\n",
33-
"+--------+--------+--------+--------+\n"\
34-
"| 'ABC' | 'AAA' | 'BBB' | 'CCC' |\n"\
35-
"+--------+--------+--------+--------+\n"\
36-
"| String | String | String | String |\n"\
37-
"+--------+--------+--------+--------+\n"\
38-
"| ABC | AAA | BBB | CCC |\n"\
39-
"+--------+--------+--------+--------+\n"
40-
};
41-
const auto & queries = std::get<1>(GetParam());
47+
const auto & queries = GetParam().queries;
4248
for (size_t i = 0; i < queries.size(); ++i) {
49+
4350
const auto & query = queries.at(i);
44-
client_->Select(query,
45-
[& queries, i](const Block& block) {
46-
if (block.GetRowCount() == 0 || block.GetColumnCount() == 0)
47-
return;
48-
EXPECT_EQ(1UL, block.GetRowCount());
49-
EXPECT_EQ(i == 0 ? 3UL: 4UL, block.GetColumnCount());
50-
51-
std::stringstream sstr;
52-
sstr << PrettyPrintBlock{block};
53-
auto result = sstr.str();
54-
std::cout << "query => " << queries.at(i) <<"\n" << PrettyPrintBlock{block};
55-
ASSERT_EQ(expect_results.at(i), result);
56-
}
57-
);
51+
const auto & expected = GetParam().expected_names[i];
52+
53+
client_->Select(query, [query, expected](const Block& block) {
54+
if (block.GetRowCount() == 0 || block.GetColumnCount() == 0)
55+
return;
56+
57+
EXPECT_EQ(1UL, block.GetRowCount());
58+
59+
EXPECT_EQ(expected, getColumnNames(block))
60+
<< "For query: " << query;
61+
});
5862
}
5963
}
6064

@@ -70,7 +74,8 @@ INSTANTIATE_TEST_SUITE_P(ClientColumnNames, AbnormalColumnNamesClientTest,
7074
.SetSendRetries(1)
7175
.SetPingBeforeQuery(true)
7276
.SetCompressionMethod(CompressionMethod::None),
73-
{"select 123,231,113", "select 'ABC','AAA','BBB','CCC'"}
77+
{"select 123,231,113", "select 'ABC','AAA','BBB','CCC'"},
78+
{"123,231,113", "'ABC','AAA','BBB','CCC'"},
7479
}
7580
));
7681

ut/abnormal_column_names_test.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)