Skip to content

Commit faa85e7

Browse files
committed
Add doc tests
1 parent 682fc7a commit faa85e7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/dumps.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
//!
1212
//! Dump imports are [performed at launch](https://docs.meilisearch.com/reference/features/configuration.html#import-dump) using an option.
1313
//! [Batch size](https://docs.meilisearch.com/reference/features/configuration.html#dump-batch-size) can also be set at this time.
14+
//!
15+
//! # Example
16+
//!
17+
//! ```no_run
18+
//! # use meilisearch_sdk::{client::*, errors::*, dumps::*};
19+
//! # use futures_await_test::async_test;
20+
//! # use std::{thread::sleep, time::Duration};
21+
//! # futures::executor::block_on(async move {
22+
//! #
23+
//! let client = Client::new("http://localhost:7700", "masterKey");
24+
//!
25+
//! // Create a dump
26+
//! let dump_info = client.create_dump().await.unwrap();
27+
//! assert!(matches!(dump_info.status, DumpStatus::InProgress));
28+
//!
29+
//! // Wait for MeiliSearch to proceed
30+
//! sleep(Duration::from_secs(5));
31+
//!
32+
//! // Check the status of the dump
33+
//! let dump_info = client.get_dump_status(&dump_info.uid).await.unwrap();
34+
//! assert!(matches!(dump_info.status, DumpStatus::Done));
35+
//! # });
36+
//! ```
1437
1538
use crate::{client::Client, errors::Error, request::*};
1639
use serde::Deserialize;
@@ -44,6 +67,21 @@ impl<'a> Client<'a> {
4467
/// Triggers a dump creation process.
4568
/// Once the process is complete, a dump is created in the [dumps directory](https://docs.meilisearch.com/reference/features/configuration.html#dumps-destination).
4669
/// If the dumps directory does not exist yet, it will be created.
70+
///
71+
/// # Example
72+
///
73+
/// ```no_run
74+
/// # use meilisearch_sdk::{client::*, errors::*, dumps::*};
75+
/// # use futures_await_test::async_test;
76+
/// # use std::{thread::sleep, time::Duration};
77+
/// # futures::executor::block_on(async move {
78+
/// #
79+
/// # let client = Client::new("http://localhost:7700", "masterKey");
80+
/// #
81+
/// let dump_info = client.create_dump().await.unwrap();
82+
/// assert!(matches!(dump_info.status, DumpStatus::InProgress));
83+
/// # });
84+
/// ```
4785
pub async fn create_dump(&self) -> Result<DumpInfo, Error> {
4886
request::<(), DumpInfo>(
4987
&format!("{}/dumps", self.host),
@@ -55,6 +93,22 @@ impl<'a> Client<'a> {
5593
}
5694

5795
/// Get the status of a dump creation process using [the uid](DumpInfo::uid) returned after calling the [dump creation method](Client::create_dump).
96+
///
97+
/// # Example
98+
///
99+
/// ```no_run
100+
/// # use meilisearch_sdk::{client::*, errors::*, dumps::*};
101+
/// # use futures_await_test::async_test;
102+
/// # use std::{thread::sleep, time::Duration};
103+
/// # futures::executor::block_on(async move {
104+
/// #
105+
/// # let client = Client::new("http://localhost:7700", "masterKey");
106+
/// # let dump_info = client.create_dump().await.unwrap();
107+
/// # sleep(Duration::from_secs(5));
108+
/// #
109+
/// let dump_info = client.get_dump_status(&dump_info.uid).await.unwrap();
110+
/// # });
111+
/// ```
58112
pub async fn get_dump_status(&self, dump_uid: &str) -> Result<DumpInfo, Error> {
59113
request::<(), DumpInfo>(
60114
&format!("{}/dumps/{}/status", self.host, dump_uid),

0 commit comments

Comments
 (0)