-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds helpers for running containers via Podman. Moves controlling starting/stopping Minio for unit tests into the relevant unit test modules. Corrects some CI issues (i.e. clippy not being able to fail builds).
- Loading branch information
Showing
11 changed files
with
177 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ members = [ | |
"common", | ||
"storage", | ||
|
||
"testing-utils", | ||
|
||
"agent", | ||
"archiver", | ||
"ctl", | ||
|
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 was deleted.
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,8 @@ | ||
[package] | ||
name = "satori-testing-utils" | ||
license.workspace = true | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
rand = "0.8.5" |
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,4 @@ | ||
mod minio; | ||
mod podman; | ||
|
||
pub use self::{minio::MinioDriver, podman::PodmanDriver}; |
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,33 @@ | ||
use crate::PodmanDriver; | ||
|
||
pub struct MinioDriver { | ||
pub podman: PodmanDriver, | ||
pub endpoint: String, | ||
} | ||
|
||
impl Default for MinioDriver { | ||
fn default() -> Self { | ||
let port = rand::random::<u16>() % 1000 + 9000; | ||
|
||
let podman = PodmanDriver::new( | ||
"docker.io/minio/minio", | ||
&[&format!("{port}:9000")], | ||
&["MINIO_ACCESS_KEY=minioadmin", "MINIO_SECRET_KEY=minioadmin"], | ||
&["server", "/data"], | ||
); | ||
|
||
let endpoint = format!("http://localhost:{}", port); | ||
|
||
Self { podman, endpoint } | ||
} | ||
} | ||
|
||
impl MinioDriver { | ||
pub fn stop(&self) { | ||
self.podman.stop(); | ||
} | ||
|
||
pub fn endpoint(&self) -> String { | ||
self.endpoint.clone() | ||
} | ||
} |
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,60 @@ | ||
use std::process::Command; | ||
|
||
pub struct PodmanDriver { | ||
container_id: String, | ||
} | ||
|
||
impl PodmanDriver { | ||
pub fn new(image: &str, ports: &[&str], env_vars: &[&str], args: &[&str]) -> Self { | ||
// Build Podman args | ||
let mut podman_args = vec!["run".to_string(), "--detach".to_string()]; | ||
|
||
for port in ports.iter() { | ||
podman_args.push("-p".to_string()); | ||
podman_args.push(port.to_string()); | ||
} | ||
|
||
for var in env_vars.iter() { | ||
podman_args.push("-e".to_string()); | ||
podman_args.push(var.to_string()); | ||
} | ||
|
||
podman_args.push(image.to_string()); | ||
|
||
for arg in args.iter() { | ||
podman_args.push(arg.to_string()); | ||
} | ||
|
||
// Start the container | ||
let container_start = Command::new("podman").args(podman_args).output().unwrap(); | ||
println!("Container start: {:?}", container_start); | ||
|
||
if container_start.status.success() && container_start.status.code().unwrap() == 0 { | ||
let container_id = String::from_utf8(container_start.stdout) | ||
.unwrap() | ||
.trim() | ||
.to_string(); | ||
println!("Container ID: {container_id}"); | ||
|
||
Self { container_id } | ||
} else { | ||
panic!("Failed to start container"); | ||
} | ||
} | ||
|
||
pub fn stop(&self) { | ||
// Stop the container | ||
let container_stop = Command::new("podman") | ||
.args(vec!["stop", &self.container_id]) | ||
.output() | ||
.unwrap(); | ||
println!("Container stop: {:?}", container_stop); | ||
|
||
// Remove the container | ||
let container_remove = Command::new("podman") | ||
.args(vec!["rm", &self.container_id]) | ||
.output() | ||
.unwrap(); | ||
println!("Container remove: {:?}", container_remove); | ||
} | ||
} |