Skip to content

Commit

Permalink
Add test for upload_to_container_streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hansen committed Aug 12, 2024
1 parent 98d7286 commit 5fe26b7
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions tests/container_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ async fn prune_containers_test(docker: Docker) -> Result<(), Error> {
Ok(())
}

async fn archive_container_test(docker: Docker) -> Result<(), Error> {
async fn archive_container_test(docker: Docker, streaming_upload: bool) -> Result<(), Error> {
let image = if cfg!(windows) {
format!("{}microsoft/nanoserver", registry_http_addr())
} else {
Expand Down Expand Up @@ -588,20 +588,43 @@ async fn archive_container_test(docker: Docker) -> Result<(), Error> {
)
.await?;

let _ = &docker
.upload_to_container(
"integration_test_archive_container",
Some(UploadToContainerOptions {
path: if cfg!(windows) {
"C:\\Windows\\Logs"
} else {
"/tmp"
},
..Default::default()
}),
payload.into(),
)
.await?;
if streaming_upload {
// Make payload live for the lifetime of the test and convert it to an async Bytes stream.
// Normally you would use an existing async stream.
let payload = Box::new(payload).leak();
let payload = payload.chunks(32);
let payload = futures_util::stream::iter(payload.map(bytes::Bytes::from));

let _ = &docker
.upload_to_container_streaming(
"integration_test_archive_container",
Some(UploadToContainerOptions {
path: if cfg!(windows) {
"C:\\Windows\\Logs"
} else {
"/tmp"
},
..Default::default()
}),
payload,
)
.await?;
} else {
let _ = &docker
.upload_to_container(
"integration_test_archive_container",
Some(UploadToContainerOptions {
path: if cfg!(windows) {
"C:\\Windows\\Logs"
} else {
"/tmp"
},
..Default::default()
}),
payload.into(),
)
.await?;
}

let res = docker.download_from_container(
"integration_test_archive_container",
Expand Down Expand Up @@ -904,7 +927,8 @@ fn integration_test_prune_containers() {

#[test]
fn integration_test_archive_containers() {
connect_to_docker_and_run!(archive_container_test);
connect_to_docker_and_run!(|docker| archive_container_test(docker, true));
connect_to_docker_and_run!(|docker| archive_container_test(docker, false));
}

#[test]
Expand Down

0 comments on commit 5fe26b7

Please sign in to comment.