Skip to content

Commit

Permalink
refactor: pass single Into<String> to cap_add, cap_drop
Browse files Browse the repository at this point in the history
  • Loading branch information
nicmr committed Oct 27, 2024
1 parent 7c85132 commit 94ed34f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions testcontainers/src/core/image/image_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ pub trait ImageExt<I: Image> {
fn with_privileged(self, privileged: bool) -> ContainerRequest<I>;

/// Adds the capabilities to the container
fn with_cap_add(self, capabilities: impl IntoIterator<Item = String>) -> ContainerRequest<I>;
fn with_cap_add(self, capability: impl Into<String>) -> ContainerRequest<I>;

/// Drops the capabilities from the container's capabilities
fn with_cap_drop(self, capabilities: impl IntoIterator<Item = String>) -> ContainerRequest<I>;
fn with_cap_drop(self, capability: impl Into<String>) -> ContainerRequest<I>;

/// cgroup namespace mode for the container. Possible values are:
/// - [`CgroupnsMode::Private`]: the container runs in its own private cgroup namespace
Expand Down Expand Up @@ -212,22 +212,22 @@ impl<RI: Into<ContainerRequest<I>>, I: Image> ImageExt<I> for RI {
}
}

fn with_cap_add(self, capabilities: impl IntoIterator<Item = String>) -> ContainerRequest<I> {
fn with_cap_add(self, capability: impl Into<String>) -> ContainerRequest<I> {
let mut container_req = self.into();
container_req
.cap_add
.get_or_insert_with(Vec::new)
.extend(capabilities);
.push(capability.into());

container_req
}

fn with_cap_drop(self, capabilities: impl IntoIterator<Item = String>) -> ContainerRequest<I> {
fn with_cap_drop(self, capability: impl Into<String>) -> ContainerRequest<I> {
let mut container_req = self.into();
container_req
.cap_drop
.get_or_insert_with(Vec::new)
.extend(capabilities);
.push(capability.into());

container_req
}
Expand Down
4 changes: 2 additions & 2 deletions testcontainers/src/runners/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ mod tests {
let image = GenericImage::new("hello-world", "latest");
let expected_capability = "NET_ADMIN";
let container = image
.with_cap_add(vec![expected_capability.to_string()])
.with_cap_add(expected_capability.to_string())
.start()
.await?;

Expand All @@ -598,7 +598,7 @@ mod tests {
let image = GenericImage::new("hello-world", "latest");
let expected_capability = "AUDIT_WRITE";
let container = image
.with_cap_drop(vec![expected_capability.to_string()])
.with_cap_drop(expected_capability.to_string())
.start()
.await?;

Expand Down

0 comments on commit 94ed34f

Please sign in to comment.