Registry testing - part 8

This commit is contained in:
mdecimus
2026-03-18 19:17:43 +01:00
parent 544598c840
commit 7ae6654735
69 changed files with 2518 additions and 2550 deletions

View File

@@ -300,174 +300,6 @@ async fn init_imap_tests(delete_if_exists: bool) -> IMAPTest {
}
}
pub trait AssertResult: Sized {
fn assert_folders<'x>(
self,
expected: impl IntoIterator<Item = (&'x str, impl IntoIterator<Item = &'x str>)>,
match_all: bool,
) -> Self;
fn assert_response_code(self, code: &str) -> Self;
fn assert_contains(self, text: &str) -> Self;
fn assert_count(self, text: &str, occurrences: usize) -> Self;
fn assert_equals(self, text: &str) -> Self;
fn into_response_code(self) -> String;
fn into_highest_modseq(self) -> String;
fn into_uid_validity(self) -> String;
fn into_append_uid(self) -> String;
fn into_copy_uid(self) -> String;
fn into_modseq(self) -> String;
}
impl AssertResult for Vec<String> {
fn assert_folders<'x>(
self,
expected: impl IntoIterator<Item = (&'x str, impl IntoIterator<Item = &'x str>)>,
match_all: bool,
) -> Self {
let mut match_count = 0;
'outer: for (mailbox_name, flags) in expected.into_iter() {
for result in self.iter() {
if result.contains(&format!("\"{}\"", mailbox_name)) {
for flag in flags {
if !flag.is_empty() && !result.contains(flag) {
panic!("Expected mailbox {} to have flag {}", mailbox_name, flag);
}
}
match_count += 1;
continue 'outer;
}
}
panic!("Mailbox {} is not present.", mailbox_name);
}
if match_all && match_count != self.len() - 1 {
panic!(
"Expected {} mailboxes, but got {}: {:?}",
match_count,
self.len() - 1,
self.iter().collect::<Vec<_>>()
);
}
self
}
fn assert_response_code(self, code: &str) -> Self {
if !self.last().unwrap().contains(&format!("[{}]", code)) {
panic!(
"Response code {:?} not found, got {:?}",
code,
self.last().unwrap()
);
}
self
}
fn assert_contains(self, text: &str) -> Self {
for line in &self {
if line.contains(text) {
return self;
}
}
panic!("Expected response to contain {:?}, got {:?}", text, self);
}
fn assert_count(self, text: &str, occurrences: usize) -> Self {
assert_eq!(
self.iter().filter(|l| l.contains(text)).count(),
occurrences,
"Expected {} occurrences of {:?}, found {} in {:?}.",
occurrences,
text,
self.iter().filter(|l| l.contains(text)).count(),
self
);
self
}
fn assert_equals(self, text: &str) -> Self {
for line in &self {
if line == text {
return self;
}
}
panic!("Expected response to be {:?}, got {:?}", text, self);
}
fn into_response_code(self) -> String {
if let Some((_, code)) = self.last().unwrap().split_once('[')
&& let Some((code, _)) = code.split_once(']')
{
return code.to_string();
}
panic!("No response code found in {:?}", self.last().unwrap());
}
fn into_append_uid(self) -> String {
if let Some((_, code)) = self.last().unwrap().split_once("[APPENDUID ")
&& let Some((code, _)) = code.split_once(']')
&& let Some((_, uid)) = code.split_once(' ')
{
return uid.to_string();
}
panic!("No APPENDUID found in {:?}", self.last().unwrap());
}
fn into_copy_uid(self) -> String {
for line in &self {
if let Some((_, code)) = line.split_once("[COPYUID ")
&& let Some((code, _)) = code.split_once(']')
&& let Some((_, uid)) = code.rsplit_once(' ')
{
return uid.to_string();
}
}
panic!("No COPYUID found in {:?}", self);
}
fn into_highest_modseq(self) -> String {
for line in &self {
if let Some((_, value)) = line.split_once("HIGHESTMODSEQ ") {
if let Some((value, _)) = value.split_once(']') {
return value.to_string();
} else if let Some((value, _)) = value.split_once(')') {
return value.to_string();
} else {
panic!("No HIGHESTMODSEQ delimiter found in {:?}", line);
}
}
}
panic!("No HIGHESTMODSEQ entries found in {:?}", self);
}
fn into_modseq(self) -> String {
for line in &self {
if let Some((_, value)) = line.split_once("MODSEQ (") {
if let Some((value, _)) = value.split_once(')') {
return value.to_string();
} else {
panic!("No MODSEQ delimiter found in {:?}", line);
}
}
}
panic!("No MODSEQ entries found in {:?}", self);
}
fn into_uid_validity(self) -> String {
for line in &self {
if let Some((_, value)) = line.split_once("UIDVALIDITY ") {
if let Some((value, _)) = value.split_once(']') {
return value.to_string();
} else if let Some((value, _)) = value.split_once(')') {
return value.to_string();
} else {
panic!("No UIDVALIDITY delimiter found in {:?}", line);
}
}
}
panic!("No UIDVALIDITY entries found in {:?}", self);
}
}
pub fn expand_uid_list(list: &str) -> AHashSet<u32> {
let mut items = AHashSet::new();
for uid in list.split(',') {