Skip to content

Commit 4284a9c

Browse files
committed
Retuned client-ydb_value_ut and client-ydb_params_ut
1 parent f84c1e3 commit 4284a9c

File tree

3 files changed

+396
-207
lines changed

3 files changed

+396
-207
lines changed

tests/unit/client/CMakeLists.txt

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ add_ydb_test(NAME client-oauth2_ut
8080
unit
8181
)
8282

83-
# add_ydb_test(NAME client-ydb_params_ut
84-
# SOURCES
85-
# params/params_ut.cpp
86-
# LINK_LIBRARIES
87-
# yutil
88-
# cpp-testing-unittest_main
89-
# YDB-CPP-SDK::Params
90-
# YDB-CPP-SDK::YsonValue
91-
# LABELS
92-
# unit
93-
# )
83+
add_ydb_test(NAME client-ydb_params_ut
84+
SOURCES
85+
params/params_ut.cpp
86+
LINK_LIBRARIES
87+
yutil
88+
cpp-testing-unittest_main
89+
YDB-CPP-SDK::Params
90+
LABELS
91+
unit
92+
)
9493

9594
add_ydb_test(NAME client-ydb_result_ut
9695
SOURCES
@@ -104,16 +103,14 @@ add_ydb_test(NAME client-ydb_result_ut
104103
unit
105104
)
106105

107-
# add_ydb_test(NAME client-ydb_value_ut
108-
# SOURCES
109-
# value/value_ut.cpp
110-
# LINK_LIBRARIES
111-
# yutil
112-
# cpp-testing-unittest_main
113-
# YDB-CPP-SDK::Value
114-
# YDB-CPP-SDK::JsonValue
115-
# YDB-CPP-SDK::YsonValue
116-
# YDB-CPP-SDK::Params
117-
# LABELS
118-
# unit
119-
# )
106+
add_ydb_test(NAME client-ydb_value_ut
107+
SOURCES
108+
value/value_ut.cpp
109+
LINK_LIBRARIES
110+
yutil
111+
cpp-testing-unittest_main
112+
YDB-CPP-SDK::Value
113+
YDB-CPP-SDK::Params
114+
LABELS
115+
unit
116+
)

tests/unit/client/params/params_ut.cpp

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#include <ydb-cpp-sdk/client/params/params.h>
22

3-
#include <ydb/public/lib/yson_value/ydb_yson_value.h>
4-
53
#include <library/cpp/testing/unittest/registar.h>
64
#include <library/cpp/testing/unittest/tests_data.h>
5+
#include <google/protobuf/text_format.h>
6+
#include <src/api/protos/ydb_value.pb.h>
77

88
using namespace NYdb;
99

1010
using TExpectedErrorException = yexception;
1111

12+
void CheckProtoValue(const Ydb::Value& value, const TString& expected) {
13+
TStringType protoStr;
14+
google::protobuf::TextFormat::PrintToString(value, &protoStr);
15+
UNIT_ASSERT_NO_DIFF(protoStr, expected);
16+
}
17+
1218
Y_UNIT_TEST_SUITE(ParamsBuilder) {
1319
Y_UNIT_TEST(Build) {
1420
auto params = TParamsBuilder()
@@ -27,15 +33,18 @@ Y_UNIT_TEST_SUITE(ParamsBuilder) {
2733
.Build()
2834
.Build();
2935

30-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()),
31-
R"(List<Uint64?>)");
32-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param1")),
33-
R"([[10u];#])");
36+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()), "List<Uint64?>");
3437

35-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()),
36-
R"(String)");
37-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param2")),
38-
R"("test")");
38+
CheckProtoValue(params.GetValue("$param1")->GetProto(),
39+
"items {\n"
40+
" uint64_value: 10\n"
41+
"}\n"
42+
"items {\n"
43+
" null_flag_value: NULL_VALUE\n"
44+
"}\n");
45+
46+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()), "String");
47+
CheckProtoValue(params.GetValue("$param2")->GetProto(), "bytes_value: \"test\"\n");
3948
}
4049

4150
Y_UNIT_TEST(BuildFromValue) {
@@ -62,15 +71,23 @@ Y_UNIT_TEST_SUITE(ParamsBuilder) {
6271
.AddParam("$param2", value2)
6372
.Build();
6473

65-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()),
66-
R"(Utf8)");
67-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param1")),
68-
R"("test1")");
69-
70-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()),
71-
R"(List<Tuple<Int32,String>?>)");
72-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param2")),
73-
R"([[[-11;"test2"]];#])");
74+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()), "Utf8");
75+
76+
CheckProtoValue(params.GetValue("$param1")->GetProto(), "text_value: \"test1\"\n");
77+
78+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()), "List<Tuple<Int32,String>?>");
79+
CheckProtoValue(params.GetValue("$param2")->GetProto(),
80+
"items {\n"
81+
" items {\n"
82+
" int32_value: -11\n"
83+
" }\n"
84+
" items {\n"
85+
" bytes_value: \"test2\"\n"
86+
" }\n"
87+
"}\n"
88+
"items {\n"
89+
" null_flag_value: NULL_VALUE\n"
90+
"}\n");
7491
}
7592

7693
Y_UNIT_TEST(BuildWithTypeInfo) {
@@ -106,15 +123,17 @@ Y_UNIT_TEST_SUITE(ParamsBuilder) {
106123
.Build()
107124
.Build();
108125

109-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()),
110-
R"(List<String>)");
111-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param1")),
112-
R"(["str1";"str2"])");
113-
114-
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()),
115-
R"(Uint32?)");
116-
UNIT_ASSERT_NO_DIFF(FormatValueYson(*params.GetValue("$param2")),
117-
R"(#)");
126+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param1")->GetType()), "List<String>");
127+
CheckProtoValue(params.GetValue("$param1")->GetProto(),
128+
"items {\n"
129+
" bytes_value: \"str1\"\n"
130+
"}\n"
131+
"items {\n"
132+
" bytes_value: \"str2\"\n"
133+
"}\n");
134+
135+
UNIT_ASSERT_NO_DIFF(FormatType(params.GetValue("$param2")->GetType()), "Uint32?");
136+
CheckProtoValue(params.GetValue("$param2")->GetProto(), "null_flag_value: NULL_VALUE\n");
118137
}
119138

120139
Y_UNIT_TEST(MissingParam) {

0 commit comments

Comments
 (0)