-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(jstzd): add integration test for pulling image
- Loading branch information
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use anyhow::Result; | ||
use bollard::{image::ListImagesOptions, secret::ImageSummary, Docker}; | ||
use jstzd::docker::{GenericImage, Image}; | ||
|
||
// search image locally | ||
async fn search_local_image( | ||
image_uri: String, | ||
client: Arc<Docker>, | ||
) -> Result<Vec<ImageSummary>> { | ||
let filters = [("reference".to_string(), vec![image_uri])] | ||
.into_iter() | ||
.collect::<HashMap<_, _>>(); | ||
let images = &client | ||
.list_images(Some(ListImagesOptions::<String> { | ||
all: true, | ||
filters, | ||
..Default::default() | ||
})) | ||
.await; | ||
match images { | ||
Ok(images) => Ok(images.clone()), | ||
Err(_) => Err(anyhow::anyhow!("Image not found")), | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_pull_image() -> Result<()> { | ||
let docker = Docker::connect_with_socket_defaults().unwrap(); | ||
let docker = Arc::new(docker); | ||
let image = GenericImage::new("busybox").with_tag("stable"); | ||
let _ = docker.remove_image(&image.image_uri(), None, None).await; | ||
image.pull_image(docker.clone()).await?; | ||
let expected_image_digest = | ||
"sha256:7db2ddde018a2a56e929855445bc7f30bc83db514a23404bd465a07d2770ac5f"; | ||
let images = search_local_image(image.image_uri(), docker.clone()).await?; | ||
assert!(images.iter().any(|image| image.id == expected_image_digest)); | ||
let _ = docker.remove_image(&image.image_uri(), None, None).await; | ||
Ok(()) | ||
} |