use std::io::Write;
use super::defs::*;
use crate::test_data::*;
#[test]
fn capability_declared() {
test_require_capability("4978capa", "COMPRESS=DEFLATE");
}
#[test]
fn compress() {
let setup = set_up();
let mut client = setup.connect("4978comp");
ok_command!(client, c("COMPRESS DEFLATE"));
let mut client = client.compress();
ok_command!(client, c("LOGIN azure hunter2"));
command!(mut responses = client, c("SELECT INBOX"));
assert_tagged_ok_any(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::Exists(0) in responses
};
command!([response] = client, c("COMPRESS DEFLATE"));
assert_matches!(
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::No,
code: Some(s::RespTextCode::CompressionActive(())),
quip: _,
}),
response.response
);
}
#[test]
fn pipelined_append() {
let setup = set_up();
let mut client = setup.connect("4978pipe");
ok_command!(client, c("COMPRESS DEFLATE"));
let mut client = client.compress();
ok_command!(client, c("LOGIN azure hunter2"));
ok_command!(client, c("CREATE 4978pipe"));
ok_command!(client, c("SELECT 4978pipe"));
let mut pipelined_data = Vec::<u8>::new();
write!(
pipelined_data,
"A APPEND 4978pipe {{{}+}}\r\n",
TORTURE_TEST.len(),
)
.unwrap();
pipelined_data.extend_from_slice(TORTURE_TEST);
write!(pipelined_data, " {{{}+}}\r\n", CHRISTMAS_TREE.len()).unwrap();
pipelined_data.extend_from_slice(CHRISTMAS_TREE);
write!(pipelined_data, "\r\n").unwrap();
write!(pipelined_data, "B FETCH 1:2 RFC822\r\n").unwrap();
client.write_raw(&pipelined_data).unwrap();
let mut buffer = Vec::new();
let mut append_responses =
client.read_responses_until_tagged(&mut buffer).unwrap();
assert_tagged_ok_any(append_responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::Exists(2) in append_responses
};
let mut fetch_responses =
client.read_responses_until_tagged(&mut buffer).unwrap();
assert_tagged_ok_any(fetch_responses.pop().unwrap());
let mut has_torture_test = false;
let mut has_christmas_tree = false;
for response in fetch_responses {
let s::Response::Fetch(fetch) = response.response else {
continue;
};
let Some(mut body) =
fetch.atts.atts.into_iter().find_map(|att| match att {
s::MsgAtt::Rfc822Full(body) => Some(body),
_ => None,
})
else {
continue;
};
let mut data = Vec::<u8>::new();
body.data.read_to_end(&mut data).unwrap();
match fetch.seqnum {
1 => {
assert!(!has_torture_test);
has_torture_test = true;
assert!(
TORTURE_TEST == data.as_slice(),
"TORTURE_TEST was corrupted",
);
},
2 => {
assert!(!has_christmas_tree);
has_christmas_tree = true;
assert!(
CHRISTMAS_TREE == data.as_slice(),
"CHRISTMAS_TREE was corrupted",
);
},
n => panic!("unexpected seqnum {n}"),
};
}
assert!(has_torture_test);
assert!(has_christmas_tree);
}