diff --git a/Cargo.lock b/Cargo.lock index c70ace228..9a6c40dbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2384,7 +2384,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.8", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -2853,7 +2853,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -5285,8 +5285,7 @@ dependencies = [ [[package]] name = "tokio-bin-process" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0581e13b120b43f94b33fac60d6d7b37327e1dddad1b422b72b8dfbda0a453cd" +source = "git+https://github.com/rukai/tokio-bin-process?branch=set_env_vars#f1ff3aee18b9dd247f585b55529c1cf7fa100793" dependencies = [ "anyhow", "cargo_metadata 0.18.1", diff --git a/Cargo.toml b/Cargo.toml index be69dde5f..329676353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,8 @@ clap = { version = "4.0.4", features = ["cargo", "derive"] } async-trait = "0.1.30" typetag = "0.2.5" aws-throwaway = { version = "0.6.0", default-features = false } -tokio-bin-process = "0.6.0" +#tokio-bin-process = "0.6.0" +tokio-bin-process = { git = "https://github.com/rukai/tokio-bin-process", branch = "set_env_vars"} ordered-float = { version = "4.0.0", features = ["serde"] } shell-quote = { default-features = false, features = ["bash"], version = "0.7.0" } pretty_assertions = "1.4.0" diff --git a/custom-transforms-example/tests/test.rs b/custom-transforms-example/tests/test.rs index 393d39a6b..77b078c57 100644 --- a/custom-transforms-example/tests/test.rs +++ b/custom-transforms-example/tests/test.rs @@ -4,7 +4,9 @@ use redis::Cmd; use std::time::Duration; use test_helpers::connection::valkey_connection; use test_helpers::docker_compose::docker_compose; -use test_helpers::shotover_process::{bin_path, BinProcess, EventMatcher, Level}; +use test_helpers::shotover_process::{ + bin_path, BinProcess, BinProcessBuilder, EventMatcher, Level, +}; #[tokio::test(flavor = "multi_thread")] async fn test_custom_transform() { @@ -37,12 +39,16 @@ async fn test_custom_transform() { } async fn shotover_proxy(topology_path: &str) -> BinProcess { - let mut shotover = BinProcess::start_binary( - bin_path!("custom-transforms-example"), - "shotover", - &["-t", topology_path, "--log-format", "json"], - ) - .await; + let mut shotover = BinProcessBuilder::from_path(bin_path!("custom-transforms-example")) + .with_log_name(Some("shotover".to_owned())) + .with_args(vec![ + "-t".to_owned(), + topology_path.to_owned(), + "--log-format".to_owned(), + "json".to_owned(), + ]) + .start() + .await; tokio::time::timeout( Duration::from_secs(30), diff --git a/shotover-proxy/benches/windsock/cloud/aws.rs b/shotover-proxy/benches/windsock/cloud/aws.rs index f918cb6ab..37dfe7015 100644 --- a/shotover-proxy/benches/windsock/cloud/aws.rs +++ b/shotover-proxy/benches/windsock/cloud/aws.rs @@ -438,7 +438,7 @@ pub async fn upload_shotover(instance: &Ec2Instance) { instance .ssh() - .push_file(local_shotover_path, Path::new("shotover-bin")) + .push_file(&local_shotover_path, Path::new("shotover-bin")) .await; instance .ssh() diff --git a/test-helpers/src/docker_compose.rs b/test-helpers/src/docker_compose.rs index 54d9af136..6efa4afc2 100644 --- a/test-helpers/src/docker_compose.rs +++ b/test-helpers/src/docker_compose.rs @@ -1,5 +1,5 @@ use docker_compose_runner::*; -use std::{env, time::Duration}; +use std::time::Duration; pub use docker_compose_runner::DockerCompose; @@ -12,11 +12,6 @@ pub fn docker_compose(file_path: &str) -> DockerCompose { /// Creates a new DockerCompose running an instance of moto the AWS mocking server pub fn new_moto() -> DockerCompose { - // Overwrite any existing AWS credential env vars belonging to the user with dummy values to be sure that - // we wont hit their real AWS account in the case of a bug in shotover or the test - env::set_var("AWS_ACCESS_KEY_ID", "dummy-access-key"); - env::set_var("AWS_SECRET_ACCESS_KEY", "dummy-access-key-secret"); - docker_compose("tests/transforms/docker-compose-moto.yaml") } diff --git a/test-helpers/src/shotover_process.rs b/test-helpers/src/shotover_process.rs index 065213425..ffd63efce 100644 --- a/test-helpers/src/shotover_process.rs +++ b/test-helpers/src/shotover_process.rs @@ -1,10 +1,11 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::time::Duration; pub use tokio_bin_process::bin_path; pub use tokio_bin_process::event::{Event, Level}; pub use tokio_bin_process::event_matcher::{Count, EventMatcher, Events}; pub use tokio_bin_process::BinProcess; +pub use tokio_bin_process::BinProcessBuilder; pub struct ShotoverProcessBuilder { topology_path: String, @@ -40,8 +41,8 @@ impl ShotoverProcessBuilder { /// Hint that there is a precompiled shotover binary available. /// This binary will be used unless a profile is specified. - pub fn with_bin(mut self, bin_path: &Path) -> Self { - self.bin_path = Some(bin_path.to_owned()); + pub fn with_bin(mut self, bin_path: PathBuf) -> Self { + self.bin_path = Some(bin_path); self } @@ -71,8 +72,8 @@ impl ShotoverProcessBuilder { self } - pub async fn start(&self) -> BinProcess { - let mut shotover = self.start_inner().await; + pub async fn start(self) -> BinProcess { + let (mut shotover, event_matchers) = self.start_inner().await; tokio::time::timeout( Duration::from_secs(30), @@ -80,7 +81,7 @@ impl ShotoverProcessBuilder { &EventMatcher::new() .with_level(Level::Info) .with_message("Shotover is now accepting inbound connections"), - &self.event_matchers, + &event_matchers, ), ) .await @@ -90,37 +91,62 @@ impl ShotoverProcessBuilder { } pub async fn assert_fails_to_start( - &self, + self, expected_errors_and_warnings: &[EventMatcher], ) -> Events { self.start_inner() .await + .0 .consume_remaining_events_expect_failure(expected_errors_and_warnings) .await } - async fn start_inner(&self) -> BinProcess { - let mut args = vec!["-t", &self.topology_path, "--log-format", "json"]; - if let Some(cores) = &self.cores { - args.extend(["--core-threads", cores]); + async fn start_inner(self) -> (BinProcess, Vec) { + let mut args = vec![ + "-t".to_owned(), + self.topology_path, + "--log-format".to_owned(), + "json".to_owned(), + ]; + if let Some(cores) = self.cores { + args.extend(["--core-threads".to_owned(), cores]); } let config_path = self .config_path .clone() .unwrap_or_else(|| "config/config.yaml".to_owned()); - args.extend(["-c", &config_path]); + args.extend(["-c".to_owned(), config_path]); - let log_name = self.log_name.as_deref().unwrap_or("shotover"); + let log_name = self.log_name.unwrap_or_else(|| "shotover".to_owned()); - match (&self.profile, &self.bin_path) { + let builder = match (self.profile, self.bin_path) { (Some(profile), _) => { - BinProcess::start_binary_name("shotover-proxy", log_name, &args, Some(profile)) - .await + BinProcessBuilder::from_cargo_name("shotover-proxy".to_owned(), Some(profile)) } - (None, Some(bin_path)) => BinProcess::start_binary(bin_path, log_name, &args).await, - (None, None) => { - BinProcess::start_binary_name("shotover-proxy", log_name, &args, None).await - } - } + (None, Some(bin_path)) => BinProcessBuilder::from_path(bin_path), + (None, None) => BinProcessBuilder::from_cargo_name("shotover-proxy".to_owned(), None), + }; + let process = builder + .with_log_name(Some(log_name)) + .with_args(args) + // Overwrite any existing AWS credential env vars belonging to the user with dummy values to be sure that + // shotover wont run with their real AWS account + // + // This also enables tests to run against moto mock AWS service as shotover's AWS client will give up + // if it cant find a key even though moto will accept any key. + .with_env_vars(vec![ + ( + "AWS_ACCESS_KEY_ID".to_owned(), + "dummy-access-key".to_owned(), + ), + ( + "AWS_SECRET_ACCESS_KEY".to_owned(), + "dummy-access-key-secret".to_owned(), + ), + ]) + .start() + .await; + + (process, self.event_matchers) } }