mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
fix tests
This commit is contained in:
parent
05f08aa9db
commit
262fdc3dc6
5 changed files with 33 additions and 37 deletions
|
|
@ -954,7 +954,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 10, 0, 40])?;
|
||||
shortstr(virtual_host, &mut writer)?;
|
||||
shortstr(reserved_1, &mut writer)?;
|
||||
bit(&[reserved_2], &mut writer)?;
|
||||
bit(&[*reserved_2], &mut writer)?;
|
||||
}
|
||||
Method::ConnectionOpenOk(ConnectionOpenOk { reserved_1 }) => {
|
||||
writer.write_all(&[0, 10, 0, 41])?;
|
||||
|
|
@ -985,11 +985,11 @@ pub mod write {
|
|||
}
|
||||
Method::ChannelFlow(ChannelFlow { active }) => {
|
||||
writer.write_all(&[0, 20, 0, 20])?;
|
||||
bit(&[active], &mut writer)?;
|
||||
bit(&[*active], &mut writer)?;
|
||||
}
|
||||
Method::ChannelFlowOk(ChannelFlowOk { active }) => {
|
||||
writer.write_all(&[0, 20, 0, 21])?;
|
||||
bit(&[active], &mut writer)?;
|
||||
bit(&[*active], &mut writer)?;
|
||||
}
|
||||
Method::ChannelClose(ChannelClose {
|
||||
reply_code,
|
||||
|
|
@ -1022,7 +1022,7 @@ pub mod write {
|
|||
shortstr(exchange, &mut writer)?;
|
||||
shortstr(r#type, &mut writer)?;
|
||||
bit(
|
||||
&[passive, durable, reserved_2, reserved_3, no_wait],
|
||||
&[*passive, *durable, *reserved_2, *reserved_3, *no_wait],
|
||||
&mut writer,
|
||||
)?;
|
||||
table(arguments, &mut writer)?;
|
||||
|
|
@ -1039,7 +1039,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 40, 0, 20])?;
|
||||
short(reserved_1, &mut writer)?;
|
||||
shortstr(exchange, &mut writer)?;
|
||||
bit(&[if_unused, no_wait], &mut writer)?;
|
||||
bit(&[*if_unused, *no_wait], &mut writer)?;
|
||||
}
|
||||
Method::ExchangeDeleteOk(ExchangeDeleteOk {}) => {
|
||||
writer.write_all(&[0, 40, 0, 21])?;
|
||||
|
|
@ -1058,7 +1058,7 @@ pub mod write {
|
|||
short(reserved_1, &mut writer)?;
|
||||
shortstr(queue, &mut writer)?;
|
||||
bit(
|
||||
&[passive, durable, exclusive, auto_delete, no_wait],
|
||||
&[*passive, *durable, *exclusive, *auto_delete, *no_wait],
|
||||
&mut writer,
|
||||
)?;
|
||||
table(arguments, &mut writer)?;
|
||||
|
|
@ -1086,7 +1086,7 @@ pub mod write {
|
|||
shortstr(queue, &mut writer)?;
|
||||
shortstr(exchange, &mut writer)?;
|
||||
shortstr(routing_key, &mut writer)?;
|
||||
bit(&[no_wait], &mut writer)?;
|
||||
bit(&[*no_wait], &mut writer)?;
|
||||
table(arguments, &mut writer)?;
|
||||
}
|
||||
Method::QueueBindOk(QueueBindOk {}) => {
|
||||
|
|
@ -1117,7 +1117,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 50, 0, 30])?;
|
||||
short(reserved_1, &mut writer)?;
|
||||
shortstr(queue, &mut writer)?;
|
||||
bit(&[no_wait], &mut writer)?;
|
||||
bit(&[*no_wait], &mut writer)?;
|
||||
}
|
||||
Method::QueuePurgeOk(QueuePurgeOk { message_count }) => {
|
||||
writer.write_all(&[0, 50, 0, 31])?;
|
||||
|
|
@ -1133,7 +1133,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 50, 0, 40])?;
|
||||
short(reserved_1, &mut writer)?;
|
||||
shortstr(queue, &mut writer)?;
|
||||
bit(&[if_unused, if_empty, no_wait], &mut writer)?;
|
||||
bit(&[*if_unused, *if_empty, *no_wait], &mut writer)?;
|
||||
}
|
||||
Method::QueueDeleteOk(QueueDeleteOk { message_count }) => {
|
||||
writer.write_all(&[0, 50, 0, 41])?;
|
||||
|
|
@ -1147,7 +1147,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 60, 0, 10])?;
|
||||
long(prefetch_size, &mut writer)?;
|
||||
short(prefetch_count, &mut writer)?;
|
||||
bit(&[global], &mut writer)?;
|
||||
bit(&[*global], &mut writer)?;
|
||||
}
|
||||
Method::BasicQosOk(BasicQosOk {}) => {
|
||||
writer.write_all(&[0, 60, 0, 11])?;
|
||||
|
|
@ -1166,7 +1166,7 @@ pub mod write {
|
|||
short(reserved_1, &mut writer)?;
|
||||
shortstr(queue, &mut writer)?;
|
||||
shortstr(consumer_tag, &mut writer)?;
|
||||
bit(&[no_local, no_ack, exclusive, no_wait], &mut writer)?;
|
||||
bit(&[*no_local, *no_ack, *exclusive, *no_wait], &mut writer)?;
|
||||
table(arguments, &mut writer)?;
|
||||
}
|
||||
Method::BasicConsumeOk(BasicConsumeOk { consumer_tag }) => {
|
||||
|
|
@ -1179,7 +1179,7 @@ pub mod write {
|
|||
}) => {
|
||||
writer.write_all(&[0, 60, 0, 30])?;
|
||||
shortstr(consumer_tag, &mut writer)?;
|
||||
bit(&[no_wait], &mut writer)?;
|
||||
bit(&[*no_wait], &mut writer)?;
|
||||
}
|
||||
Method::BasicCancelOk(BasicCancelOk { consumer_tag }) => {
|
||||
writer.write_all(&[0, 60, 0, 31])?;
|
||||
|
|
@ -1196,7 +1196,7 @@ pub mod write {
|
|||
short(reserved_1, &mut writer)?;
|
||||
shortstr(exchange, &mut writer)?;
|
||||
shortstr(routing_key, &mut writer)?;
|
||||
bit(&[mandatory, immediate], &mut writer)?;
|
||||
bit(&[*mandatory, *immediate], &mut writer)?;
|
||||
}
|
||||
Method::BasicReturn(BasicReturn {
|
||||
reply_code,
|
||||
|
|
@ -1220,7 +1220,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 60, 0, 60])?;
|
||||
shortstr(consumer_tag, &mut writer)?;
|
||||
longlong(delivery_tag, &mut writer)?;
|
||||
bit(&[redelivered], &mut writer)?;
|
||||
bit(&[*redelivered], &mut writer)?;
|
||||
shortstr(exchange, &mut writer)?;
|
||||
shortstr(routing_key, &mut writer)?;
|
||||
}
|
||||
|
|
@ -1232,7 +1232,7 @@ pub mod write {
|
|||
writer.write_all(&[0, 60, 0, 70])?;
|
||||
short(reserved_1, &mut writer)?;
|
||||
shortstr(queue, &mut writer)?;
|
||||
bit(&[no_ack], &mut writer)?;
|
||||
bit(&[*no_ack], &mut writer)?;
|
||||
}
|
||||
Method::BasicGetOk(BasicGetOk {
|
||||
delivery_tag,
|
||||
|
|
@ -1243,7 +1243,7 @@ pub mod write {
|
|||
}) => {
|
||||
writer.write_all(&[0, 60, 0, 71])?;
|
||||
longlong(delivery_tag, &mut writer)?;
|
||||
bit(&[redelivered], &mut writer)?;
|
||||
bit(&[*redelivered], &mut writer)?;
|
||||
shortstr(exchange, &mut writer)?;
|
||||
shortstr(routing_key, &mut writer)?;
|
||||
long(message_count, &mut writer)?;
|
||||
|
|
@ -1258,7 +1258,7 @@ pub mod write {
|
|||
}) => {
|
||||
writer.write_all(&[0, 60, 0, 80])?;
|
||||
longlong(delivery_tag, &mut writer)?;
|
||||
bit(&[multiple], &mut writer)?;
|
||||
bit(&[*multiple], &mut writer)?;
|
||||
}
|
||||
Method::BasicReject(BasicReject {
|
||||
delivery_tag,
|
||||
|
|
@ -1266,15 +1266,15 @@ pub mod write {
|
|||
}) => {
|
||||
writer.write_all(&[0, 60, 0, 90])?;
|
||||
longlong(delivery_tag, &mut writer)?;
|
||||
bit(&[requeue], &mut writer)?;
|
||||
bit(&[*requeue], &mut writer)?;
|
||||
}
|
||||
Method::BasicRecoverAsync(BasicRecoverAsync { requeue }) => {
|
||||
writer.write_all(&[0, 60, 0, 100])?;
|
||||
bit(&[requeue], &mut writer)?;
|
||||
bit(&[*requeue], &mut writer)?;
|
||||
}
|
||||
Method::BasicRecover(BasicRecover { requeue }) => {
|
||||
writer.write_all(&[0, 60, 0, 110])?;
|
||||
bit(&[requeue], &mut writer)?;
|
||||
bit(&[*requeue], &mut writer)?;
|
||||
}
|
||||
Method::BasicRecoverOk(BasicRecoverOk {}) => {
|
||||
writer.write_all(&[0, 60, 0, 111])?;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// create random methods to test the ser/de code together. if they diverge, we have a bug
|
||||
// this is not perfect, if they both have the same bug it won't be found, but tha's an ok tradeoff
|
||||
// this is not perfect, if they both have the same bug it won't be found, but that's an ok tradeoff
|
||||
|
||||
use crate::methods::{FieldValue, Method, RandomMethod};
|
||||
use rand::SeedableRng;
|
||||
|
|
@ -32,14 +32,14 @@ fn pack_many_bits() {
|
|||
|
||||
#[test]
|
||||
fn random_ser_de() {
|
||||
const ITERATIONS: usize = 1000;
|
||||
const ITERATIONS: usize = 10000;
|
||||
let mut rng = rand::rngs::StdRng::from_seed([0; 32]);
|
||||
|
||||
for _ in 0..ITERATIONS {
|
||||
let method = Method::random(&mut rng);
|
||||
let mut bytes = Vec::new();
|
||||
|
||||
if let Err(err) = super::write::write_method(method.clone(), &mut bytes) {
|
||||
if let Err(err) = super::write::write_method(&method, &mut bytes) {
|
||||
eprintln!("{method:#?}");
|
||||
eprintln!("{err:?}");
|
||||
panic!("Failed to serialize");
|
||||
|
|
@ -73,7 +73,7 @@ fn nested_table() {
|
|||
eprintln!("{table:?}");
|
||||
|
||||
let mut bytes = Vec::new();
|
||||
crate::methods::write_helper::table(table.clone(), &mut bytes).unwrap();
|
||||
crate::methods::write_helper::table(&table, &mut bytes).unwrap();
|
||||
eprintln!("{bytes:?}");
|
||||
|
||||
let (rest, parsed_table) = crate::methods::parse_helper::table(&bytes).unwrap();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub fn longlong<W: Write>(value: &Longlong, writer: &mut W) -> Result<(), TransE
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn bit<W: Write>(value: &[&Bit], writer: &mut W) -> Result<(), TransError> {
|
||||
pub fn bit<W: Write>(value: &[Bit], writer: &mut W) -> Result<(), TransError> {
|
||||
// accumulate bits into bytes, starting from the least significant bit in each byte
|
||||
|
||||
// how many bits have already been packed into `current_buf`
|
||||
|
|
@ -37,7 +37,7 @@ pub fn bit<W: Write>(value: &[&Bit], writer: &mut W) -> Result<(), TransError> {
|
|||
already_filled = 0;
|
||||
}
|
||||
|
||||
let new_bit = (u8::from(*bit)) << already_filled;
|
||||
let new_bit = (u8::from(bit)) << already_filled;
|
||||
current_buf |= new_bit;
|
||||
already_filled += 1;
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ mod tests {
|
|||
let bits = [true, false, true];
|
||||
|
||||
let mut buffer = [0u8; 1];
|
||||
super::bit(&bits.map(|b| &b), &mut buffer.as_mut_slice()).unwrap();
|
||||
super::bit(&bits, &mut buffer.as_mut_slice()).unwrap();
|
||||
|
||||
assert_eq!(buffer, [0b00000101])
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ mod tests {
|
|||
];
|
||||
|
||||
let mut buffer = [0u8; 2];
|
||||
super::bit(&bits.map(|b| &b), &mut buffer.as_mut_slice()).unwrap();
|
||||
super::bit(&bits, &mut buffer.as_mut_slice()).unwrap();
|
||||
|
||||
assert_eq!(buffer, [0b00001111, 0b00001101]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,17 +19,13 @@ async fn write_start_ok_frame() {
|
|||
locales: "en_US".into(),
|
||||
});
|
||||
|
||||
methods::write::write_method(method, &mut payload).unwrap();
|
||||
|
||||
let frame = frame::Frame {
|
||||
kind: FrameType::Method,
|
||||
channel: ChannelNum::zero(),
|
||||
payload: payload.into(),
|
||||
};
|
||||
methods::write::write_method(&method, &mut payload).unwrap();
|
||||
|
||||
let mut output = Vec::new();
|
||||
|
||||
frame::write_frame(&frame, &mut output).await.unwrap();
|
||||
frame::write_frame(&mut output, FrameType::Method, ChannelNum::zero(), &payload)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
#[rustfmt::skip]
|
||||
let expected = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue