From d066f02082f7d4e37ba2f641278d9299d373a58d Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 22 Aug 2024 02:00:56 +0200 Subject: [PATCH 1/7] docs added docs for the ganachecli module --- src/trufflesuite_ganachecli/mod.rs | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/trufflesuite_ganachecli/mod.rs b/src/trufflesuite_ganachecli/mod.rs index 87bce42..3c1112a 100644 --- a/src/trufflesuite_ganachecli/mod.rs +++ b/src/trufflesuite_ganachecli/mod.rs @@ -1,19 +1,55 @@ use std::borrow::Cow; -use testcontainers::{core::WaitFor, Image}; +use testcontainers::{ + core::{ContainerPort, WaitFor}, + Image, +}; const NAME: &str = "trufflesuite/ganache-cli"; const TAG: &str = "v6.1.3"; +/// Port that the [`Ganache CLI`] container has internally. +/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`] +/// +/// [Ganache CLI]: https://github.com/trufflesuite/ganache +pub const GANACHE_CLI_PORT: ContainerPort = ContainerPort::Tcp(8545); + +/// # Module to work with the [`Ganache CLI`] inside of tests. +/// +/// Starts an instance of Meilisearch. +/// This module is based on the official [`trufflesuite/ganache-cli` docker image] documented in the [documentation]. +/// +/// # Example +/// ``` +/// use testcontainers_modules::{testcontainers::runners::SyncRunner, trufflesuite_ganachecli}; +/// +/// let instance = trufflesuite_ganachecli::GanacheCli::default() +/// .start() +/// .unwrap(); +/// let url = format!( +/// "http://{host_ip}:{host_port}", +/// host_ip = meilisearch_instance.get_host().unwrap(), +/// host_port = meilisearch_instance.get_host_port_ipv4(7700).unwrap() +/// ); +/// // do something with the started GanacheCli instance.. +/// ``` +/// +/// [Ganache CLI]: https://github.com/trufflesuite/ganache +/// [documentation]: https://github.com/trufflesuite/ganache?tab=readme-ov-file#documentation +/// [`trufflesuite/ganache-cli` docker image]: https://hub.docker.com/r/trufflesuite/ganache-cli/ #[derive(Debug, Default, Clone)] pub struct GanacheCli { cmd: GanacheCliCmd, } +/// Options to pass to the `ganache-cli` command #[derive(Debug, Clone)] pub struct GanacheCliCmd { + /// Specify the network id ganache-core will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured) pub network_id: u32, + /// Specify the number of accounts to generate at startup pub number_of_accounts: u32, + /// Use a bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation. pub mnemonic: String, } @@ -57,6 +93,10 @@ impl Image for GanacheCli { TAG } + fn expose_ports(&self) -> &[ContainerPort] { + &[GANACHE_CLI_PORT] + } + fn ready_conditions(&self) -> Vec { vec![WaitFor::message_on_stdout("Listening on localhost:")] } @@ -77,7 +117,7 @@ mod tests { let _ = pretty_env_logger::try_init(); let node = trufflesuite_ganachecli::GanacheCli::default().start()?; let host_ip = node.get_host()?; - let host_port = node.get_host_port_ipv4(8545)?; + let host_port = node.get_host_port_ipv4(GANACHE_CLI_PORT)?; let response = reqwest::blocking::Client::new() .post(format!("http://{host_ip}:{host_port}")) From 7efa0d970c1fea266ed520a09c07d029d9620f88 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 22 Aug 2024 02:14:51 +0200 Subject: [PATCH 2/7] docs: fixed unrelated change to make CI happy --- src/openldap/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openldap/mod.rs b/src/openldap/mod.rs index 4c0729e..de4beed 100644 --- a/src/openldap/mod.rs +++ b/src/openldap/mod.rs @@ -27,13 +27,15 @@ const OPENLDAP_PORT: ContainerPort = ContainerPort::Tcp(1389); /// openldap_instance.get_host_port_ipv4(1389).unwrap(), /// ); /// let mut conn = ldap3::LdapConn::new(&connection_string).unwrap(); -/// let ldap3::SearchResult(rs,_) = conn.search( -/// "ou=users,dc=example,dc=org", -/// ldap3::Scope::Subtree, -/// "(cn=ma*)", -/// vec!["cn"] -/// ).unwrap(); -/// let results:Vec<_>=rs.into_iter().map(ldap3::SearchEntry::construct).collect(); +/// let ldap3::SearchResult(rs, _) = conn +/// .search( +/// "ou=users,dc=example,dc=org", +/// ldap3::Scope::Subtree, +/// "(cn=ma*)", +/// vec!["cn"], +/// ) +/// .unwrap(); +/// let results: Vec<_> = rs.into_iter().map(ldap3::SearchEntry::construct).collect(); /// assert_eq!(results.len(), 0); /// ``` /// From 1e0ccb71ec2884213fb942687d33fe4a371c27c4 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 22 Aug 2024 18:35:01 +0200 Subject: [PATCH 3/7] fix: formatting --- src/kafka/apache.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kafka/apache.rs b/src/kafka/apache.rs index b9932db..b325f7f 100644 --- a/src/kafka/apache.rs +++ b/src/kafka/apache.rs @@ -1,4 +1,5 @@ use std::{borrow::Cow, collections::HashMap}; + use testcontainers::{ core::{ContainerPort, ContainerState, ExecCommand, WaitFor}, Image, From 0384123b7ef380fc38041c595ad6d6ed36ae1798 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 22 Aug 2024 18:58:38 +0200 Subject: [PATCH 4/7] fix: typos in the docs and test --- src/trufflesuite_ganachecli/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/trufflesuite_ganachecli/mod.rs b/src/trufflesuite_ganachecli/mod.rs index 3c1112a..5be5918 100644 --- a/src/trufflesuite_ganachecli/mod.rs +++ b/src/trufflesuite_ganachecli/mod.rs @@ -28,8 +28,8 @@ pub const GANACHE_CLI_PORT: ContainerPort = ContainerPort::Tcp(8545); /// .unwrap(); /// let url = format!( /// "http://{host_ip}:{host_port}", -/// host_ip = meilisearch_instance.get_host().unwrap(), -/// host_port = meilisearch_instance.get_host_port_ipv4(7700).unwrap() +/// host_ip = instance.get_host().unwrap(), +/// host_port = instance.get_host_port_ipv4(GANACHE_CLI_PORT).unwrap() /// ); /// // do something with the started GanacheCli instance.. /// ``` @@ -110,12 +110,12 @@ impl Image for GanacheCli { mod tests { use testcontainers::runners::SyncRunner; - use crate::trufflesuite_ganachecli; + use super::*; #[test] fn trufflesuite_ganachecli_listaccounts() -> Result<(), Box> { let _ = pretty_env_logger::try_init(); - let node = trufflesuite_ganachecli::GanacheCli::default().start()?; + let node = GanacheCli::default().start()?; let host_ip = node.get_host()?; let host_port = node.get_host_port_ipv4(GANACHE_CLI_PORT)?; From 5f1261198b1d4b22736d05e28459e246e75269c8 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 31 Aug 2024 17:01:51 +0200 Subject: [PATCH 5/7] fixed the doctest --- src/trufflesuite_ganachecli/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trufflesuite_ganachecli/mod.rs b/src/trufflesuite_ganachecli/mod.rs index 5be5918..84f9fa6 100644 --- a/src/trufflesuite_ganachecli/mod.rs +++ b/src/trufflesuite_ganachecli/mod.rs @@ -22,6 +22,7 @@ pub const GANACHE_CLI_PORT: ContainerPort = ContainerPort::Tcp(8545); /// # Example /// ``` /// use testcontainers_modules::{testcontainers::runners::SyncRunner, trufflesuite_ganachecli}; +/// use testcontainers_modules::trufflesuite_ganachecli::GANACHE_CLI_PORT /// /// let instance = trufflesuite_ganachecli::GanacheCli::default() /// .start() From a8781e009ec5a64374403e63e44ea564e756cdb7 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 31 Aug 2024 17:13:18 +0200 Subject: [PATCH 6/7] docs: fixed formatting mistake --- src/trufflesuite_ganachecli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trufflesuite_ganachecli/mod.rs b/src/trufflesuite_ganachecli/mod.rs index 84f9fa6..c10668a 100644 --- a/src/trufflesuite_ganachecli/mod.rs +++ b/src/trufflesuite_ganachecli/mod.rs @@ -22,7 +22,7 @@ pub const GANACHE_CLI_PORT: ContainerPort = ContainerPort::Tcp(8545); /// # Example /// ``` /// use testcontainers_modules::{testcontainers::runners::SyncRunner, trufflesuite_ganachecli}; -/// use testcontainers_modules::trufflesuite_ganachecli::GANACHE_CLI_PORT +/// use testcontainers_modules::trufflesuite_ganachecli::GANACHE_CLI_PORT; /// /// let instance = trufflesuite_ganachecli::GanacheCli::default() /// .start() From 30ed40af1b6d607dd8cd09583e1ce25fa65fb0f2 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 31 Aug 2024 17:16:02 +0200 Subject: [PATCH 7/7] chore: fix formatting issue --- src/trufflesuite_ganachecli/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trufflesuite_ganachecli/mod.rs b/src/trufflesuite_ganachecli/mod.rs index c10668a..e5f7886 100644 --- a/src/trufflesuite_ganachecli/mod.rs +++ b/src/trufflesuite_ganachecli/mod.rs @@ -21,8 +21,10 @@ pub const GANACHE_CLI_PORT: ContainerPort = ContainerPort::Tcp(8545); /// /// # Example /// ``` -/// use testcontainers_modules::{testcontainers::runners::SyncRunner, trufflesuite_ganachecli}; -/// use testcontainers_modules::trufflesuite_ganachecli::GANACHE_CLI_PORT; +/// use testcontainers_modules::{ +/// testcontainers::runners::SyncRunner, trufflesuite_ganachecli, +/// trufflesuite_ganachecli::GANACHE_CLI_PORT, +/// }; /// /// let instance = trufflesuite_ganachecli::GanacheCli::default() /// .start()