Skip to content

Commit 3b3ac3f

Browse files
authored
fix(docker-compose): respect TESTCONTAINERS_COMMAND (#891)
1 parent 814ff31 commit 3b3ac3f

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

testcontainers/src/compose/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(super) mod local;
77

88
pub(super) enum ComposeClient {
99
Local(local::LocalComposeCli),
10-
Containerised(containerised::ContainerisedComposeCli),
10+
Containerised(Box<containerised::ContainerisedComposeCli>),
1111
}
1212

1313
impl ComposeClient {
@@ -16,9 +16,9 @@ impl ComposeClient {
1616
}
1717

1818
pub(super) async fn new_containerised(compose_files: Vec<PathBuf>) -> Result<Self> {
19-
Ok(ComposeClient::Containerised(
19+
Ok(ComposeClient::Containerised(Box::new(
2020
containerised::ContainerisedComposeCli::new(compose_files).await?,
21-
))
21+
)))
2222
}
2323
}
2424

testcontainers/src/compose/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{collections::HashMap, path::Path, sync::Arc};
33
use crate::{
44
compose::client::ComposeInterface,
55
core::{
6-
async_container::raw::RawContainer, async_drop, client::Client, wait::WaitStrategy, WaitFor,
6+
async_container::raw::RawContainer, async_drop, client::Client, env, wait::WaitStrategy,
7+
WaitFor,
78
},
89
};
910

@@ -222,7 +223,17 @@ impl Drop for DockerCompose {
222223
let client = self.client.clone();
223224
let rmi = self.remove_images;
224225
let volumes = self.remove_volumes;
226+
let command = self
227+
.docker_client
228+
.as_ref()
229+
.map(|client| client.config.command())
230+
.unwrap_or(env::Command::Remove);
231+
225232
let drop_task = async move {
233+
if command != env::Command::Remove {
234+
return;
235+
}
236+
226237
let res = client
227238
.down(client::DownCommand {
228239
project_name,

testcontainers/src/core/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl Client {
427427
let stream = self
428428
.bollard
429429
.download_from_container(container_id, Some(options))
430-
.map_err(|err| io::Error::new(io::ErrorKind::Other, err));
430+
.map_err(io::Error::other);
431431
let reader = StreamReader::new(stream);
432432
Self::extract_file_entry(reader, target)
433433
.await

testcontainers/src/core/containers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(crate) mod request;
55
#[cfg(feature = "blocking")]
66
pub(crate) mod sync_container;
77

8-
pub use async_container::{exec::ExecResult, ContainerAsync};
8+
pub use async_container::{exec::ExecResult, raw::RawContainer, ContainerAsync};
99
pub use request::{CgroupnsMode, ContainerRequest, Host, PortMapping};
1010
#[cfg(feature = "blocking")]
1111
#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]

testcontainers/src/core/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl CopyFileFromContainer for Vec<u8> {
7575
}
7676

7777
#[async_trait(?Send)]
78-
impl<'a> CopyFileFromContainer for &'a mut Vec<u8> {
78+
impl CopyFileFromContainer for &mut Vec<u8> {
7979
type Output = ();
8080

8181
async fn copy_from_reader<R>(

testcontainers/tests/async_runner.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bollard::{
44
query_parameters::{ListImagesOptions, RemoveImageOptions},
55
Docker,
66
};
7-
use tempfile;
87
use testcontainers::{
98
core::{
109
client::ClientError,

0 commit comments

Comments
 (0)