Skip to content

Commit 682fc7a

Browse files
committed
Add test
1 parent 87c7e36 commit 682fc7a

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/dumps.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ pub async fn create_dump<'a>(client: &'a Client<'a>) -> Result<DumpInfo, Error>
7272
}
7373

7474
/// Alias for [get_dump_status](Client::get_dump_status).
75-
pub async fn get_dump_status<'a>(client: &'a Client<'a>, dump_uid: &str) -> Result<DumpInfo, Error> {
75+
pub async fn get_dump_status<'a>(
76+
client: &'a Client<'a>,
77+
dump_uid: &str,
78+
) -> Result<DumpInfo, Error> {
7679
client.get_dump_status(dump_uid).await
7780
}
81+
82+
#[cfg(test)]
83+
mod tests {
84+
use super::*;
85+
use crate::{client::*, errors::*};
86+
use futures_await_test::async_test;
87+
use std::{thread::sleep, time::Duration};
88+
89+
#[async_test]
90+
async fn test_dumps() {
91+
let client = Client::new("http://localhost:7700", "masterKey");
92+
93+
// Create a dump
94+
let dump_info = client.create_dump().await.unwrap();
95+
assert!(matches!(dump_info.status, DumpStatus::InProgress));
96+
97+
// Try to create another dump (should fail since the first dump is in progress)
98+
let failure = client.create_dump().await.unwrap_err();
99+
assert!(matches!(
100+
failure,
101+
Error::MeiliSearchError {
102+
error_code: ErrorCode::DumpAlreadyInProgress,
103+
..
104+
}
105+
));
106+
107+
// Wait for Meilisearch to do the dump
108+
sleep(Duration::from_secs(5));
109+
110+
// Assert that the dump was successful
111+
let new_dump_info = client.get_dump_status(&dump_info.uid).await.unwrap();
112+
assert!(matches!(new_dump_info.status, DumpStatus::Done));
113+
}
114+
}

0 commit comments

Comments
 (0)