Skip to content

Commit d02050c

Browse files
Merge pull request #249 from testcontainers/release/0.12.0
2 parents 99767dd + fcbf609 commit d02050c

19 files changed

+293
-185
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.12.0] - 2021-01-27
11+
12+
### Added
13+
14+
- Allow custom version for postgres image
15+
- Remove `derivative` dependency
16+
- `OrientDB` image
17+
- `Zookeeper` image
18+
19+
### Changed
20+
21+
- Move port mapping logic to `RunArgs` instead of each Image.
22+
1023
## [0.11.0] - 2020-09-30
1124

1225
### Added
@@ -59,7 +72,9 @@ Previously, this was done in a fire-and-forget way and hence led to containers n
5972
- Provide a default password for the postgres image.
6073
There seems to be an unfortunate breaking change in the postgres image that we need to cater for.
6174

62-
[Unreleased]: https://github.com/testcontainers/testcontainers-rs/compare/0.11.0...HEAD
75+
[Unreleased]: https://github.com/testcontainers/testcontainers-rs/compare/0.12.0...HEAD
76+
77+
[0.12.0]: https://github.com/testcontainers/testcontainers-rs/compare/0.11.0...0.12.0
6378

6479
[0.11.0]: https://github.com/testcontainers/testcontainers-rs/compare/0.10.0...0.11.0
6580

Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ keywords = ["docker", "testcontainers"]
77
license = "MIT OR Apache-2.0"
88
name = "testcontainers"
99
repository = "https://github.com/testcontainers/testcontainers-rs"
10-
version = "0.11.0"
10+
version = "0.12.0"
1111

1212
[dependencies]
13-
derivative = "2"
1413
hex = "0.4"
15-
hmac = "0.8"
14+
hmac = "0.10"
1615
log = "0.4"
17-
rand = "0.7"
16+
rand = "0.8"
1817
serde = { version = "1", features = ["derive"] }
1918
serde_json = "1"
2019
sha2 = "0.9"
2120

2221
[dev-dependencies]
23-
bitcoincore-rpc = "0.11"
24-
postgres = "0.17"
22+
bitcoincore-rpc = "0.12"
23+
postgres = "0.18"
2524
pretty_env_logger = "0.4"
26-
redis = "0.16"
25+
redis = "0.19"
2726
mongodb = "1.0.0"
2827
rusoto_core = "0.45"
2928
rusoto_credential = "0.45"
@@ -33,3 +32,6 @@ spectral = "0.6"
3332
reqwest = { version = "0.10", features = ["blocking"] }
3433
json = "0.12"
3534
tokio = { version = "0.2", features = ["macros"] }
35+
env_logger = "0.8"
36+
zookeeper = "0.5"
37+
orientdb-client = "0.5.1"

src/clients/cli.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Cli {
9898
command.arg("--entrypoint").arg(entrypoint);
9999
}
100100

101-
if let Some(ports) = image.ports() {
101+
if let Some(ports) = run_args.ports() {
102102
for port in &ports {
103103
command
104104
.arg("-p")
@@ -327,7 +327,6 @@ impl Ports {
327327

328328
#[cfg(test)]
329329
mod tests {
330-
use crate::core::Port;
331330
use crate::images::generic::GenericImage;
332331
use crate::{Container, Docker, Image};
333332

@@ -414,10 +413,6 @@ mod tests {
414413
self.env_vars.clone()
415414
}
416415

417-
fn ports(&self) -> Option<Vec<Port>> {
418-
None
419-
}
420-
421416
fn with_args(self, _arguments: <Self as Image>::Args) -> Self {
422417
self
423418
}
@@ -466,12 +461,11 @@ mod tests {
466461

467462
#[test]
468463
fn cli_run_command_should_expose_only_requested_ports() {
469-
let image = GenericImage::new("hello")
464+
let image = GenericImage::new("hello");
465+
let mut docker = Command::new("docker");
466+
let run_args = RunArgs::default()
470467
.with_mapped_port((123, 456))
471468
.with_mapped_port((555, 888));
472-
473-
let mut docker = Command::new("docker");
474-
let run_args = RunArgs::default();
475469
let command = Cli::build_run_command(&image, &mut docker, &run_args);
476470

477471
println!("Executing command: {:?}", command);

src/core/docker.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use crate::core::Port;
12
use crate::{Container, Image};
2-
use std::{collections::HashMap, io::Read};
3+
use std::{collections::HashMap, fmt, io::Read};
34

45
/// Defines the minimum API required for interacting with the Docker daemon.
56
pub trait Docker
@@ -18,10 +19,12 @@ where
1819
/// Container run command arguments.
1920
/// `name` - run image instance with the given name (should be explicitly set to be seen by other containers created in the same docker network).
2021
/// `network` - run image instance on the given network.
22+
/// `ports` - run image instance with the given ports mapping (if explicit mappings is not defined, all image ports will be automatically exposed and mapped on random host ports).
2123
#[derive(Debug, Clone, Default)]
2224
pub struct RunArgs {
2325
name: Option<String>,
2426
network: Option<String>,
27+
ports: Option<Vec<Port>>,
2528
}
2629

2730
impl RunArgs {
@@ -39,13 +42,24 @@ impl RunArgs {
3942
}
4043
}
4144

45+
pub fn with_mapped_port<P: Into<Port>>(mut self, port: P) -> Self {
46+
let mut ports = self.ports.unwrap_or_default();
47+
ports.push(port.into());
48+
self.ports = Some(ports);
49+
self
50+
}
51+
4252
pub(crate) fn network(&self) -> Option<String> {
4353
self.network.clone()
4454
}
4555

4656
pub(crate) fn name(&self) -> Option<String> {
4757
self.name.clone()
4858
}
59+
60+
pub(crate) fn ports(&self) -> Option<Vec<Port>> {
61+
self.ports.clone()
62+
}
4963
}
5064

5165
/// The exposed ports of a running container.
@@ -71,11 +85,13 @@ impl Ports {
7185
}
7286

7387
/// Log streams of running container (stdout & stderr).
74-
#[derive(derivative::Derivative)]
75-
#[derivative(Debug)]
7688
pub struct Logs {
77-
#[derivative(Debug = "ignore")]
7889
pub stdout: Box<dyn Read>,
79-
#[derivative(Debug = "ignore")]
8090
pub stderr: Box<dyn Read>,
8191
}
92+
93+
impl fmt::Debug for Logs {
94+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95+
f.debug_struct("Logs").finish()
96+
}
97+
}

src/core/image.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ where
8585
/// Returns the volumes this instance was created with.
8686
fn volumes(&self) -> Self::Volumes;
8787

88-
/// Returs the ports mapping requested for the image.
89-
/// If not explicit port mappings is defined, all image ports will be automatically
90-
/// exposed and mapped on random host ports.
91-
fn ports(&self) -> Option<Vec<Port>>;
92-
9388
/// Re-configures the current instance of this image with the given arguments.
9489
fn with_args(self, arguments: Self::Args) -> Self;
9590

src/images.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ pub mod dynamodb_local;
33
pub mod elasticmq;
44
pub mod generic;
55
pub mod mongo;
6+
pub mod orientdb;
67
pub mod parity_parity;
78
pub mod postgres;
89
pub mod redis;
910
pub mod trufflesuite_ganachecli;
11+
pub mod zookeeper;

src/images/coblox_bitcoincore.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::core::Port;
21
use crate::core::{Container, Docker, Image, WaitForMessage};
32
use hex::encode;
43
use hmac::{Hmac, Mac, NewMac};
@@ -11,7 +10,6 @@ use std::{collections::HashMap, env::var, thread::sleep, time::Duration};
1110
pub struct BitcoinCore {
1211
tag: String,
1312
arguments: BitcoinCoreImageArgs,
14-
ports: Option<Vec<Port>>,
1513
}
1614

1715
impl BitcoinCore {
@@ -235,10 +233,6 @@ impl Image for BitcoinCore {
235233
HashMap::new()
236234
}
237235

238-
fn ports(&self) -> Option<Vec<Port>> {
239-
self.ports.clone()
240-
}
241-
242236
fn with_args(self, arguments: <Self as Image>::Args) -> Self {
243237
BitcoinCore { arguments, ..self }
244238
}
@@ -249,7 +243,6 @@ impl Default for BitcoinCore {
249243
BitcoinCore {
250244
tag: "0.20.0".into(),
251245
arguments: BitcoinCoreImageArgs::default(),
252-
ports: None,
253246
}
254247
}
255248
}
@@ -261,13 +254,6 @@ impl BitcoinCore {
261254
..self
262255
}
263256
}
264-
265-
pub fn with_mapped_port<P: Into<Port>>(mut self, port: P) -> Self {
266-
let mut ports = self.ports.unwrap_or_default();
267-
ports.push(port.into());
268-
self.ports = Some(ports);
269-
self
270-
}
271257
}
272258

273259
#[cfg(test)]

src/images/dynamodb_local.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::core::Port;
21
use crate::{Container, Docker, Image, WaitForMessage};
32
use std::{collections::HashMap, env::var, thread::sleep, time::Duration};
43

@@ -23,15 +22,13 @@ impl IntoIterator for DynamoDbArgs {
2322
pub struct DynamoDb {
2423
tag: String,
2524
arguments: DynamoDbArgs,
26-
ports: Option<Vec<Port>>,
2725
}
2826

2927
impl Default for DynamoDb {
3028
fn default() -> Self {
3129
DynamoDb {
3230
tag: DEFAULT_TAG.to_string(),
3331
arguments: DynamoDbArgs {},
34-
ports: None,
3532
}
3633
}
3734
}
@@ -80,10 +77,6 @@ impl Image for DynamoDb {
8077
HashMap::new()
8178
}
8279

83-
fn ports(&self) -> Option<Vec<Port>> {
84-
self.ports.clone()
85-
}
86-
8780
fn with_args(self, arguments: <Self as Image>::Args) -> Self {
8881
DynamoDb { arguments, ..self }
8982
}
@@ -96,11 +89,4 @@ impl DynamoDb {
9689
..self
9790
}
9891
}
99-
100-
pub fn with_mapped_port<P: Into<Port>>(mut self, port: P) -> Self {
101-
let mut ports = self.ports.unwrap_or_default();
102-
ports.push(port.into());
103-
self.ports = Some(ports);
104-
self
105-
}
10692
}

src/images/elasticmq.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::core::Port;
21
use crate::{Container, Docker, Image, WaitForMessage};
32
use std::collections::HashMap;
43

@@ -21,15 +20,13 @@ impl IntoIterator for ElasticMQArgs {
2120
pub struct ElasticMQ {
2221
tag: String,
2322
arguments: ElasticMQArgs,
24-
ports: Option<Vec<Port>>,
2523
}
2624

2725
impl Default for ElasticMQ {
2826
fn default() -> Self {
2927
ElasticMQ {
3028
tag: DEFAULT_TAG.to_string(),
3129
arguments: ElasticMQArgs {},
32-
ports: None,
3330
}
3431
}
3532
}
@@ -64,10 +61,6 @@ impl Image for ElasticMQ {
6461
HashMap::new()
6562
}
6663

67-
fn ports(&self) -> Option<Vec<Port>> {
68-
self.ports.clone()
69-
}
70-
7164
fn with_args(self, arguments: <Self as Image>::Args) -> Self {
7265
ElasticMQ { arguments, ..self }
7366
}
@@ -80,11 +73,4 @@ impl ElasticMQ {
8073
..self
8174
}
8275
}
83-
84-
pub fn with_mapped_port<P: Into<Port>>(mut self, port: P) -> Self {
85-
let mut ports = self.ports.unwrap_or_default();
86-
ports.push(port.into());
87-
self.ports = Some(ports);
88-
self
89-
}
9076
}

0 commit comments

Comments
 (0)