Skip to content

Commit 6de3294

Browse files
committed
Add test
1 parent 5a8bf5a commit 6de3294

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/client.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,78 @@ mod tests {
25372537
}
25382538
}
25392539

2540+
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
2541+
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
2542+
async fn test_get_quota_root() {
2543+
{
2544+
let response = b"* QUOTAROOT Sent Userquota\r\n\
2545+
* QUOTA Userquota (STORAGE 4855 48576)\r\n\
2546+
A0001 OK Getquotaroot completed (0.004 + 0.000 + 0.004 secs).\r\n"
2547+
.to_vec();
2548+
2549+
let mock_stream = MockStream::new(response);
2550+
let mut session = mock_session!(mock_stream);
2551+
let (quotaroots, quota) = dbg!(session.get_quota_root("Sent").await.unwrap());
2552+
assert_eq!(
2553+
str::from_utf8(&session.stream.inner.written_buf).unwrap(),
2554+
"A0001 GETQUOTAROOT \"Sent\"\r\n"
2555+
);
2556+
assert_eq!(
2557+
quotaroots,
2558+
vec![QuotaRoot {
2559+
mailbox_name: "Sent".to_string(),
2560+
quota_root_names: vec!["Userquota".to_string(),],
2561+
},],
2562+
);
2563+
assert_eq!(
2564+
quota,
2565+
vec![Quota {
2566+
root_name: "Userquota".to_string(),
2567+
resources: vec![QuotaResource {
2568+
name: QuotaResourceName::Storage,
2569+
usage: 4855,
2570+
limit: 48576,
2571+
}],
2572+
}]
2573+
);
2574+
assert_eq!(quota[0].resources[0].get_usage_percentage(), 9);
2575+
}
2576+
2577+
{
2578+
let response = b"* QUOTAROOT \"INBOX\" \"#19\"\r\n\
2579+
* QUOTA \"#19\" (STORAGE 0 0)\r\n\
2580+
A0001 OK GETQUOTAROOT successful.\r\n"
2581+
.to_vec();
2582+
2583+
let mock_stream = MockStream::new(response);
2584+
let mut session = mock_session!(mock_stream);
2585+
let (quotaroots, quota) = session.get_quota_root("INBOX").await.unwrap();
2586+
assert_eq!(
2587+
str::from_utf8(&session.stream.inner.written_buf).unwrap(),
2588+
"A0001 GETQUOTAROOT \"INBOX\"\r\n"
2589+
);
2590+
assert_eq!(
2591+
quotaroots,
2592+
vec![QuotaRoot {
2593+
mailbox_name: "INBOX".to_string(),
2594+
quota_root_names: vec!["#19".to_string(),],
2595+
},],
2596+
);
2597+
assert_eq!(
2598+
quota,
2599+
vec![Quota {
2600+
root_name: "#19".to_string(),
2601+
resources: vec![QuotaResource {
2602+
name: QuotaResourceName::Storage,
2603+
usage: 0,
2604+
limit: 0,
2605+
}],
2606+
}]
2607+
);
2608+
assert_eq!(quota[0].resources[0].get_usage_percentage(), 0);
2609+
}
2610+
}
2611+
25402612
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
25412613
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
25422614
async fn test_parsing_error() {

0 commit comments

Comments
 (0)