Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add name parameter to RunnableImage #549

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions testcontainers/src/core/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl Display for Host {
pub struct RunnableImage<I: Image> {
image: I,
image_args: I::Args,
image_name: Option<String>,
DDtKey marked this conversation as resolved.
Show resolved Hide resolved
image_tag: Option<String>,
container_name: Option<String>,
network: Option<String>,
Expand Down Expand Up @@ -228,11 +229,13 @@ impl<I: Image> RunnableImage<I> {
}

pub fn descriptor(&self) -> String {
if let Some(tag) = &self.image_tag {
format!("{}:{tag}", self.image.name())
} else {
format!("{}:{}", self.image.name(), self.image.tag())
}
let original_name = self.image.name();
let original_tag = self.image.tag();

let name = self.image_name.as_ref().unwrap_or(&original_name);
let tag = self.image_tag.as_ref().unwrap_or(&original_tag);

format!("{name}:{tag}")
}

pub fn ready_conditions(&self) -> Vec<WaitFor> {
Expand Down Expand Up @@ -272,6 +275,15 @@ impl<I: Image> RunnableImage<I> {
}
}

/// Overrides the fully qualified image name (consists of `{domain}/{owner}/{image}`).
/// Can be used to specify a custom registry or owner.
pub fn with_name(self, name: impl Into<String>) -> Self {
Self {
image_name: Some(name.into()),
..self
}
}

/// There is no guarantee that the specified tag for an image would result in a
/// running container. Users of this API are advised to use this at their own risk.
pub fn with_tag(self, tag: impl Into<String>) -> Self {
Expand Down Expand Up @@ -350,6 +362,7 @@ impl<I: Image> From<(I, I::Args)> for RunnableImage<I> {
Self {
image,
image_args,
image_name: None,
image_tag: None,
container_name: None,
network: None,
Expand Down
Loading