From df28a6e11beac606a42d3efa650bfe732214f352 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 23 Nov 2024 18:40:35 +0000 Subject: [PATCH] doc: turns out ye can have doctests, code in teh documentationt aht can be tested wild --- Cargo.lock | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++++ src/lib.rs | 20 +++++++++++++++----- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7c9b2a..4b15ff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,28 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -1073,6 +1095,30 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-test" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7" +dependencies = [ + "async-stream", + "bytes", + "futures-core", + "tokio", + "tokio-stream", +] + [[package]] name = "tokio-util" version = "0.7.12" @@ -1369,6 +1415,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "tokio-test", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fc502bd..d35e233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,10 @@ edition = "2021" # for making teh requests reqwest = { version = "0.12", features = ["json"] } +# for testing async stuff +tokio-test = "0.4" + + # parsing teh results serde_json = { version = "1.0", features = ["raw_value"] } serde = { version = "1.0.215", features = ["derive"] } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2705941..56b49e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,9 +135,11 @@ impl Client { /// # Examples /// /// ```rust + /// # tokio_test::block_on(async { /// use wolves_oxidised::{Client, WolvesUser}; /// let client = Client::new("https://cp.ulwolves.ie/api", None); - /// let result: Vec = client.get_members("api_key_club_1"); + /// let result: Vec = client.get_members("api_key_club_1").await; + /// # }) /// ``` pub async fn get_members(&self, api_key: &str) -> Vec { self.get_bulk::("get_members", api_key).await @@ -148,17 +150,21 @@ impl Client { /// # Examples /// No instance API key set /// ```rust + /// # tokio_test::block_on(async { /// use wolves_oxidised::{Client, WolvesCNS}; /// let client = Client::new("https://cp.ulwolves.ie/api", None); - /// let result: Vec = client.get_committees(); + /// let result: Vec = client.get_committees().await; /// assert_eq!(result.len(), 0); + /// # }) /// ``` /// /// Instance API key set, will return details if there are no other errors /// ```rust + /// # tokio_test::block_on(async { /// use wolves_oxidised::{Client, WolvesCNS}; /// let client = Client::new("https://cp.ulwolves.ie/api", Some("api_key_instance")); - /// let result: Vec = client.get_committees(); + /// let result: Vec = client.get_committees().await; + /// # }) /// ``` pub async fn get_committees(&self) -> Vec { if let Some(api_key) = &self.base_key { @@ -176,17 +182,21 @@ impl Client { /// # Examples /// No instance API key set /// ```rust + /// # tokio_test::block_on(async { /// use wolves_oxidised::Client; /// let client = Client::new("https://cp.ulwolves.ie/api", None); - /// let result: Option = client.get_member("example@example.ie"); + /// let result: Option = client.get_member("example@example.ie").await; /// assert!(result.is_none()); + /// # }) /// ``` /// /// Instance API key set, will return details if there are no other errors /// ```rust + /// # tokio_test::block_on(async { /// use wolves_oxidised::Client; /// let client = Client::new("https://cp.ulwolves.ie/api", Some("api_key_instance")); - /// let result: Option = client.get_member("example@example.ie"); + /// let result: Option = client.get_member("example@example.ie").await; + /// # }) /// ``` pub async fn get_member(self, email: &str) -> Option { // if the key isnt set then we cant do anything.