You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/container.rs
+88-16Lines changed: 88 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,38 @@
1
1
//! This module holds the optional testcontainer utility functions of the SDK.
2
2
//!
3
-
//! It uses the [testcontainers](https://docs.rs/testcontainers/latest/testcontainers/) crate to start a test container for the [EventSourcingDB](https://www.eventsourcingdb.io/).
3
+
//! It uses the [testcontainers] crate to start a test container for the [EventSourcingDB](https://www.eventsourcingdb.io/).
4
+
//!
4
5
//! It uses the builder pattern to configure the container and start it.
6
+
//!
7
+
//! # How to use
8
+
//!
9
+
//! ## Shortcut suitable for most use cases
10
+
//! This starts a container with the default settings which is most likely what you want.
11
+
//! ```
12
+
//! # use eventsourcingdb_client_rust::container::Container;
13
+
//! # tokio_test::block_on(async {
14
+
//! let container = Container::start_default().await;
15
+
//! // let client = container.get_client().await;
16
+
//! # });
17
+
//! ```
18
+
//!
19
+
//! ## Custom configuration
20
+
//! This allows you to configure the container to your needs.
21
+
//! ```
22
+
//! # use eventsourcingdb_client_rust::container::Container;
23
+
//! # tokio_test::block_on(async {
24
+
//! let container = Container::builder()
25
+
//! .with_image_tag("v1.0.0")
26
+
//! .with_port(3000)
27
+
//! .with_api_token("mysecrettoken")
28
+
//! .start().await;
29
+
//! // let client = container.get_client().await;
30
+
//! # });
31
+
//! ```
32
+
//!
33
+
//! ## Stopping the container
34
+
//! The container will be stopped automatically when it is dropped.
35
+
//! You can also stop it manually by calling the [Container::stop] method.
/// This is the port that you can use to connect to the database. This will be a random port that is mapped to the internal port configured via [ContainerBuilder::with_port].
121
193
///
122
194
/// # Errors
123
195
/// This function will return an error if the container is not running (e.g. because it crashed) or if the host could not be retrieved
@@ -128,7 +200,7 @@ impl Container {
128
200
.await?)
129
201
}
130
202
131
-
/// Get the complete base URL for the database
203
+
/// Get the complete http base URL for the database.
132
204
///
133
205
/// # Errors
134
206
/// This function will return an error if the container is not running (e.g. because it crashed) or if the host could not be retrieved
@@ -138,7 +210,7 @@ impl Container {
138
210
Ok(Url::parse(&format!("http://{host}:{port}"))?)
139
211
}
140
212
141
-
/// Get the API token for the database
213
+
/// Get the API token for the database.
142
214
///
143
215
/// # Errors
144
216
/// This function will return an error if the container is not running (e.g. because it crashed) or if the host could not be retrieved
@@ -147,7 +219,7 @@ impl Container {
147
219
self.api_token.as_str()
148
220
}
149
221
150
-
/// Check if the container is running
222
+
/// Check if the container is running.
151
223
///
152
224
/// Since we make sure the container is running via the typesystem, this will always return true.
153
225
/// This method is still included to match the interface of the Go SDK.
0 commit comments