mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-06 06:53:12 +00:00
types: Test correct list validation
Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
This commit is contained in:
@@ -187,20 +187,35 @@ SEASTAR_TEST_CASE(test_drop_table_with_si_and_mv) {
|
||||
|
||||
SEASTAR_TEST_CASE(test_list_elements_validation) {
|
||||
return do_with_cql_env_thread([](cql_test_env& e) {
|
||||
auto test_inline = [&] (sstring value, bool should_throw) {
|
||||
auto cql = sprint("INSERT INTO tbl (a, b) VALUES(1, ['%s'])", value);
|
||||
if (should_throw) {
|
||||
BOOST_REQUIRE_THROW(e.execute_cql(cql).get(), exceptions::invalid_request_exception);
|
||||
} else {
|
||||
BOOST_REQUIRE_NO_THROW(e.execute_cql(cql).get());
|
||||
}
|
||||
};
|
||||
e.execute_cql("CREATE TABLE tbl (a int, b list<date>, PRIMARY KEY (a))").get();
|
||||
BOOST_REQUIRE_THROW(
|
||||
e.execute_cql("INSERT INTO tbl (a, b) VALUES(1, ['definietly not a date value'])").get(),
|
||||
exceptions::invalid_request_exception);
|
||||
test_inline("definietly not a date value", true);
|
||||
test_inline("2015-05-03", false);
|
||||
e.execute_cql("CREATE TABLE tbl2 (a int, b list<text>, PRIMARY KEY (a))").get();
|
||||
auto id = e.prepare("INSERT INTO tbl2 (a, b) VALUES(?, ?)").get0();
|
||||
auto my_list_type = list_type_impl::get_instance(utf8_type, true);
|
||||
std::vector<cql3::raw_value> raw_values;
|
||||
raw_values.emplace_back(cql3::raw_value::make_value(int32_type->decompose(int32_t{1})));
|
||||
auto values = my_list_type->decompose(make_list_value(my_list_type, {sstring(1, '\255')}));
|
||||
raw_values.emplace_back(cql3::raw_value::make_value(values));
|
||||
BOOST_REQUIRE_THROW(
|
||||
e.execute_prepared(id, raw_values).get(),
|
||||
exceptions::invalid_request_exception);
|
||||
auto test_bind = [&] (sstring value, bool should_throw) {
|
||||
auto my_list_type = list_type_impl::get_instance(utf8_type, true);
|
||||
std::vector<cql3::raw_value> raw_values;
|
||||
raw_values.emplace_back(cql3::raw_value::make_value(int32_type->decompose(int32_t{1})));
|
||||
auto values = my_list_type->decompose(make_list_value(my_list_type, {value}));
|
||||
raw_values.emplace_back(cql3::raw_value::make_value(values));
|
||||
if (should_throw) {
|
||||
BOOST_REQUIRE_THROW(
|
||||
e.execute_prepared(id, raw_values).get(),
|
||||
exceptions::invalid_request_exception);
|
||||
} else {
|
||||
BOOST_REQUIRE_NO_THROW(e.execute_prepared(id, raw_values).get());
|
||||
}
|
||||
};
|
||||
test_bind(sstring(1, '\255'), true);
|
||||
test_bind("proper utf8 string", false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user