added test for mssql ReturnValue (#1892)

* added test for mssql ReturnValue

* fixed warnings: unused import: `DataType`
This commit is contained in:
Keiji, Yoshimi 2022-06-09 07:49:12 +09:00 committed by GitHub
parent 1f91724927
commit 3cfa734b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -4,8 +4,11 @@ use bytes::{Buf, Bytes};
use crate::error::Error;
use crate::mssql::io::MssqlBufExt;
use crate::mssql::protocol::col_meta_data::Flags;
#[cfg(test)]
use crate::mssql::protocol::type_info::DataType;
use crate::mssql::protocol::type_info::TypeInfo;
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct ReturnValue {
param_ordinal: u16,
@ -48,3 +51,27 @@ impl ReturnValue {
})
}
}
#[test]
fn test_get() {
#[rustfmt::skip]
let mut buf = Bytes::from_static(&[
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x26, 4, 4, 1, 0, 0, 0, 0xfe, 0, 0, 0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]);
let return_value = ReturnValue::get(&mut buf).unwrap();
assert_eq!(return_value.param_ordinal, 0);
assert_eq!(return_value.param_name, "");
assert_eq!(
return_value.status,
ReturnValueStatus::from_bits_truncate(1)
);
assert_eq!(return_value.user_type, 0);
assert_eq!(return_value.flags, Flags::from_bits_truncate(0));
assert_eq!(return_value.type_info, TypeInfo::new(DataType::IntN, 4));
assert_eq!(
return_value.value,
Some(Bytes::from_static(&[0x01, 0, 0, 0]))
);
}

View File

@ -660,3 +660,14 @@ impl Collation {
buf.push(self.sort);
}
}
#[test]
fn test_get() {
#[rustfmt::skip]
let mut buf = Bytes::from_static(&[
0x26, 4, 4, 1, 0, 0, 0, 0xfe, 0, 0, 0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]);
let type_info = TypeInfo::get(&mut buf).unwrap();
assert_eq!(type_info, TypeInfo::new(DataType::IntN, 4));
}