Skip to content

Commit f3cad89

Browse files
Fixed chaotic tests
1 parent f66033e commit f3cad89

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

chaotic/integration_tests/tests/lib/array.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <userver/chaotic/array.hpp>
88
#include <userver/chaotic/primitive.hpp>
99
#include <userver/chaotic/validators.hpp>
10+
#include <userver/formats/json.hpp>
1011

1112
USERVER_NAMESPACE_BEGIN
1213

@@ -37,7 +38,7 @@ TEST(Array, OfIntWithValidators) {
3738

3839
const auto kJson1 = formats::json::MakeArray("foo");
3940
UEXPECT_THROW_MSG(
40-
kJson1.As<Arr>(), chaotic::Error, "Error at path '/': Too short array, minimum length=2, given=1"
41+
kJson1.As<Arr>(), chaotic::Error<userver::formats::json::Value>, "Error at path '/': Too short array, minimum length=2, given=1"
4142
);
4243
}
4344

chaotic/integration_tests/tests/lib/primitive.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ TEST(Primitive, IntMinMax) {
6969
int x = kJson["foo"].As<Int>();
7070
EXPECT_EQ(x, 1);
7171

72-
UEXPECT_THROW_MSG(kJson["bar"].As<Int>(), chaotic::Error, "Error at path 'bar': Invalid value, minimum=1, given=0");
73-
UEXPECT_THROW_MSG(kJson["zoo"].As<Int>(), chaotic::Error, "Error at path 'zoo': Invalid value, maximum=5, given=6");
72+
UEXPECT_THROW_MSG(kJson["bar"].As<Int>(), chaotic::Error<userver::formats::json::Value>,
73+
"Error at path 'bar': Invalid value, minimum=1, given=0");
74+
UEXPECT_THROW_MSG(kJson["zoo"].As<Int>(), chaotic::Error<userver::formats::json::Value>,
75+
"Error at path 'zoo': Invalid value, maximum=5, given=6");
7476
}
7577

7678
TEST(Primitive, UserTypeMinMax) {
@@ -80,8 +82,10 @@ TEST(Primitive, UserTypeMinMax) {
8082
MyInt x = kJson["foo"].As<Int>();
8183
EXPECT_EQ(x.value, 1);
8284

83-
UEXPECT_THROW_MSG(kJson["bar"].As<Int>(), chaotic::Error, "Error at path 'bar': Invalid value, minimum=1, given=0");
84-
UEXPECT_THROW_MSG(kJson["zoo"].As<Int>(), chaotic::Error, "Error at path 'zoo': Invalid value, maximum=5, given=6");
85+
UEXPECT_THROW_MSG(kJson["bar"].As<Int>(), chaotic::Error<userver::formats::json::Value>,
86+
"Error at path 'bar': Invalid value, minimum=1, given=0");
87+
UEXPECT_THROW_MSG(kJson["zoo"].As<Int>(), chaotic::Error<userver::formats::json::Value>,
88+
"Error at path 'zoo': Invalid value, maximum=5, given=6");
8589
}
8690

8791
TEST(Primitive, StringMinMaxLength) {
@@ -93,10 +97,12 @@ TEST(Primitive, StringMinMaxLength) {
9397
EXPECT_EQ(x, "12");
9498

9599
UEXPECT_THROW_MSG(
96-
kLocalJson["1"].As<Str>(), chaotic::Error, "Error at path '1': Too short string, minimum length=2, given=1"
100+
kLocalJson["1"].As<Str>(), chaotic::Error<userver::formats::json::Value>,
101+
"Error at path '1': Too short string, minimum length=2, given=1"
97102
);
98103
UEXPECT_THROW_MSG(
99-
kLocalJson["6"].As<Str>(), chaotic::Error, "Error at path '6': Too long string, maximum length=5, given=6"
104+
kLocalJson["6"].As<Str>(), chaotic::Error<userver::formats::json::Value>,
105+
"Error at path '6': Too long string, maximum length=5, given=6"
100106
);
101107
}
102108

@@ -110,7 +116,7 @@ TEST(Primitive, StringPattern) {
110116
std::string x = kLocalJson["1"].As<Str>();
111117
EXPECT_EQ(x, "foo");
112118

113-
UEXPECT_THROW_MSG(kLocalJson["2"].As<Str>(), chaotic::Error, "doesn't match regex");
119+
UEXPECT_THROW_MSG(kLocalJson["2"].As<Str>(), chaotic::Error<userver::formats::json::Value>, "doesn't match regex");
114120
}
115121

116122
USERVER_NAMESPACE_END

chaotic/integration_tests/tests/render/minmax.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ USERVER_NAMESPACE_BEGIN
1010
TEST(MinMax, ExclusiveInt) {
1111
auto json = formats::json::MakeObject("foo", 1);
1212
UEXPECT_THROW_MSG(
13-
json.As<ns::IntegerObject>(), chaotic::Error, "Error at path 'foo': Invalid value, exclusive minimum=1, given=1"
13+
json.As<ns::IntegerObject>(), chaotic::Error<userver::formats::json::Value>,
14+
"Error at path 'foo': Invalid value, exclusive minimum=1, given=1"
1415
);
1516

1617
json = formats::json::MakeObject("foo", 2);
@@ -19,7 +20,7 @@ TEST(MinMax, ExclusiveInt) {
1920
json = formats::json::MakeObject("foo", 20);
2021
UEXPECT_THROW_MSG(
2122
json.As<ns::IntegerObject>(),
22-
chaotic::Error,
23+
chaotic::Error<userver::formats::json::Value>,
2324
"Error at path 'foo': Invalid value, exclusive maximum=20, given=20"
2425
);
2526

@@ -30,24 +31,28 @@ TEST(MinMax, ExclusiveInt) {
3031
TEST(MinMax, String) {
3132
auto json = formats::json::MakeObject("bar", "");
3233
UEXPECT_THROW_MSG(
33-
json.As<ns::IntegerObject>(), chaotic::Error, "Error at path 'bar': Too short string, minimum length=2, given=0"
34+
json.As<ns::IntegerObject>(), chaotic::Error<userver::formats::json::Value>,
35+
"Error at path 'bar': Too short string, minimum length=2, given=0"
3436
);
3537

3638
json = formats::json::MakeObject("bar", "longlonglong");
3739
UEXPECT_THROW_MSG(
38-
json.As<ns::IntegerObject>(), chaotic::Error, "Error at path 'bar': Too long string, maximum length=5, given=12"
40+
json.As<ns::IntegerObject>(), chaotic::Error<userver::formats::json::Value>,
41+
"Error at path 'bar': Too long string, maximum length=5, given=12"
3942
);
4043
}
4144

4245
TEST(MinMax, Array) {
4346
auto json = formats::json::MakeObject("zoo", formats::json::MakeArray(1));
4447
UEXPECT_THROW_MSG(
45-
json.As<ns::IntegerObject>(), chaotic::Error, "Error at path 'zoo': Too short array, minimum length=2, given=1"
48+
json.As<ns::IntegerObject>(), chaotic::Error<userver::formats::json::Value>,
49+
"Error at path 'zoo': Too short array, minimum length=2, given=1"
4650
);
4751

4852
json = formats::json::MakeObject("zoo", formats::json::MakeArray(1, 2, 3, 4, 5, 6, 7, 8));
4953
UEXPECT_THROW_MSG(
50-
json.As<ns::IntegerObject>(), chaotic::Error, "Error at path 'zoo': Too long array, maximum length=5, given=8"
54+
json.As<ns::IntegerObject>(), chaotic::Error<userver::formats::json::Value>,
55+
"Error at path 'zoo': Too long array, maximum length=5, given=8"
5156
);
5257
}
5358

chaotic/integration_tests/tests/render/simple.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ TEST(Simple, DefaultFieldValue) {
4545
TEST(Simple, IntegerMinimum) {
4646
auto json = formats::json::MakeObject("int3", 1, "int", -10);
4747
UEXPECT_THROW_MSG(
48-
json.As<ns::SimpleObject>(), chaotic::Error, "Error at path 'int': Invalid value, minimum=-1, given=-10"
48+
json.As<ns::SimpleObject>(), chaotic::Error<userver::formats::json::Value>,
49+
"Error at path 'int': Invalid value, minimum=-1, given=-10"
4950
);
5051
}
5152

5253
TEST(Simple, IntegerMaximum) {
5354
auto json = formats::json::MakeObject("int3", 1, "int", 11);
5455
UEXPECT_THROW_MSG(
55-
json.As<ns::SimpleObject>(), chaotic::Error, "Error at path 'int': Invalid value, maximum=10, given=11"
56+
json.As<ns::SimpleObject>(), chaotic::Error<userver::formats::json::Value>,
57+
"Error at path 'int': Invalid value, maximum=10, given=11"
5658
);
5759
}
5860

@@ -78,7 +80,8 @@ TEST(Simple, IntegerFormat) {
7880
TEST(Simple, ObjectWithRefType) {
7981
auto json = formats::json::MakeObject("integer", 0);
8082
UEXPECT_THROW_MSG(
81-
json.As<ns::ObjectWithRef>(), chaotic::Error, "Error at path 'integer': Invalid value, minimum=1, given=0"
83+
json.As<ns::ObjectWithRef>(), chaotic::Error<userver::formats::json::Value>,
84+
"Error at path 'integer': Invalid value, minimum=1, given=0"
8285
);
8386
}
8487

@@ -141,7 +144,9 @@ TEST(Simple, ObjectExtraMemberFalse) {
141144
TEST(Simple, ObjectWithAdditionalPropertiesFalseStrict) {
142145
auto json = formats::json::MakeObject("foo", 1, "bar", 2);
143146
UEXPECT_THROW_MSG(
144-
json.As<ns::ObjectWithAdditionalPropertiesFalseStrict>(), std::runtime_error, "Unknown property 'bar'"
147+
json.As<ns::ObjectWithAdditionalPropertiesFalseStrict>(),
148+
chaotic::Error<userver::formats::json::Value>,
149+
"Unknown property 'bar'"
145150
);
146151
}
147152

@@ -156,7 +161,7 @@ TEST(Simple, IntegerEnum) {
156161
auto json2 = formats::json::MakeObject("one", 5);
157162
UEXPECT_THROW_MSG(
158163
json2["one"].As<ns::IntegerEnum>(),
159-
chaotic::Error,
164+
chaotic::Error<userver::formats::json::Value>,
160165
"Error at path 'one': Invalid enum value (5) for type ns::IntegerEnum"
161166
);
162167

@@ -181,7 +186,7 @@ TEST(Simple, StringEnum) {
181186
auto json2 = formats::json::MakeObject("one", "zoo");
182187
UEXPECT_THROW_MSG(
183188
json2["one"].As<ns::StringEnum>(),
184-
chaotic::Error,
189+
chaotic::Error<userver::formats::json::Value>,
185190
"Error at path 'one': Invalid enum value (zoo) for type ns::StringEnum"
186191
);
187192

0 commit comments

Comments
 (0)