Skip to content

Commit 040f1ef

Browse files
committed
Add UDT request tests
Adds tests for converting JS UDT into Rust CQL values.
1 parent 11907c9 commit 040f1ef

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/tests/request_values_tests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use scylla::{
33
value::CqlTime,
44
};
55
use std::{
6+
borrow::Cow,
67
net::{IpAddr, Ipv4Addr},
78
str::FromStr,
89
};
@@ -33,6 +34,22 @@ pub fn tests_from_value_get_type(test: String) -> ComplexType {
3334
"List" => (CqlType::List, Some(CqlType::Text), None),
3435
"Map" => (CqlType::Map, Some(CqlType::Ascii), Some(CqlType::Double)),
3536
"Set" => (CqlType::Set, Some(CqlType::Int), None),
37+
"UserDefinedType" => {
38+
return ComplexType::from_udt(
39+
&[
40+
(
41+
Cow::Owned("field1".to_owned()),
42+
ColumnType::Native(NativeType::Text),
43+
),
44+
(
45+
Cow::Owned("field2".to_owned()),
46+
ColumnType::Native(NativeType::Int),
47+
),
48+
],
49+
"name".to_owned(),
50+
"keyspace".to_owned(),
51+
)
52+
}
3653
"SmallInt" => (CqlType::SmallInt, None, None),
3754
"TinyInt" => (CqlType::TinyInt, None, None),
3855
"Time" => (CqlType::Time, None, None),
@@ -83,6 +100,14 @@ pub fn tests_from_value(test: String, value: &QueryParameterWrapper) {
83100
(CqlValue::Ascii("Text2".to_owned()), CqlValue::Double(0.2)),
84101
]),
85102
"Set" => CqlValue::Set(vec![CqlValue::Int(4), CqlValue::Int(7), CqlValue::Int(15)]),
103+
"UserDefinedType" => CqlValue::UserDefinedType {
104+
keyspace: "keyspace".to_owned(),
105+
name: "name".to_owned(),
106+
fields: vec![
107+
("field1".to_owned(), Some(CqlValue::Text("Test".to_owned()))),
108+
("field2".to_owned(), Some(CqlValue::Int(1))),
109+
],
110+
},
86111
"SmallInt" => CqlValue::SmallInt(1_i16),
87112
"TinyInt" => CqlValue::TinyInt(-1_i8),
88113
"Time" => CqlValue::Time(CqlTime(4312)),

test/unit/query-parameter-tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const testCases = [
3232
["List", ["Test value", "Some other funny value"]],
3333
["Map", { Text: 0.1, Text2: 0.2 }],
3434
["Set", [4, 7, 15]],
35+
["UserDefinedType", { field1: "Test", field2: 1 }],
3536
["SmallInt", 1],
3637
["TinyInt", -1],
3738
["Time", new LocalTime(Long.fromInt(4312))],

0 commit comments

Comments
 (0)