Skip to content

Commit

Permalink
Adds e2e tests for verify-config cli. (metalbear-co#1998)
Browse files Browse the repository at this point in the history
* Adds e2e tests for verify-config cli.

* improve tests // use dedicated config file

* changelog

* docs

* notices to not modify tests
  • Loading branch information
meowjesty authored Oct 9, 2023
1 parent a5488d5 commit f9b5ba1
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/1997.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding some e2e tests for to protect against breaking changes in the cli.
11 changes: 11 additions & 0 deletions tests/configs/default_ide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"feature": {
"network": {
"incoming": "mirror",
"outgoing": true
},
"fs": "read",
"env": true
}
}

1 change: 1 addition & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ mod pause;
mod target;
mod targetless;
mod traffic;
mod verify_config;

pub mod utils;
16 changes: 16 additions & 0 deletions tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,22 @@ pub async fn run_ls(args: Option<Vec<&str>>, namespace: Option<&str>) -> TestPro
run_mirrord(mirrord_args, Default::default()).await
}

/// Runs `mirrord verify-config [--ide] "/path/config.json"`.
///
/// ## Attention
///
/// The `verify-config` tests are here to guarantee that your changes do not break backwards
/// compatability, so you should not modify them, only add new tests (unless breakage is
/// wanted/required).
pub async fn run_verify_config(args: Option<Vec<&str>>) -> TestProcess {
let mut mirrord_args = vec!["verify-config"];
if let Some(args) = args {
mirrord_args.extend(args);
}

run_mirrord(mirrord_args, Default::default()).await
}

#[fixture]
pub async fn kube_client() -> Client {
let mut config = Config::infer().await.unwrap();
Expand Down
95 changes: 95 additions & 0 deletions tests/src/verify_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/// # Attention
///
/// If any of these tests fails, then you're attempting a breaking change!
///
/// Do **NOT** modify these tests if you change the cli for `verify-config`, unless we're ok with
/// a breaking change!
///
/// You should probably only add new tests here.
#[cfg(test)]
mod verify_config {
use std::time::Duration;

use rstest::rstest;

use crate::utils::{config_dir, run_verify_config};

/// Tests `verify-config` with `path` and `--ide` args, which should be:
///
/// ```sh
/// mirrord verify-config --ide /path/to/config.json
/// ```
#[rstest]
#[tokio::test]
#[timeout(Duration::from_secs(30))]
pub async fn path_ide_verify_config(config_dir: &std::path::PathBuf) {
let mut config_path = config_dir.clone();
config_path.push("default_ide.json");

let mut process = run_verify_config(Some(vec![
"--ide",
config_path.to_str().expect("Valid config path!"),
]))
.await;

assert!(process.wait().await.success());
}

/// Tests `verify-config` with only `path` as an arg:
///
/// ```sh
/// mirrord verify-config /path/to/config.json
/// ```
#[rstest]
#[tokio::test]
#[timeout(Duration::from_secs(30))]
pub async fn no_ide_verify_config(config_dir: &std::path::PathBuf) {
let mut config_path = config_dir.clone();
config_path.push("default_ide.json");

let mut process = run_verify_config(Some(vec![config_path
.to_str()
.expect("Valid config path!")]))
.await;

assert!(process.wait().await.success());
}

/// Tests `verify-config` with only `--ide` as an arg:
///
/// The process should fail, as path is a required arg!
///
/// ```sh
/// mirrord verify-config --ide
/// ```
#[rstest]
#[tokio::test]
#[timeout(Duration::from_secs(30))]
pub async fn no_path_verify_config(config_dir: &std::path::PathBuf) {
let mut config_path = config_dir.clone();
config_path.push("default_ide.json");

let mut process = run_verify_config(Some(vec!["--ide"])).await;

assert!(!process.wait().await.success());
}

/// Tests `verify-config` without args:
///
/// The process should fail, as path is a required arg!
///
/// ```sh
/// mirrord verify-config
/// ```
#[rstest]
#[tokio::test]
#[timeout(Duration::from_secs(30))]
pub async fn no_path_no_ide_verify_config(config_dir: &std::path::PathBuf) {
let mut config_path = config_dir.clone();
config_path.push("default_ide.json");

let mut process = run_verify_config(None).await;

assert!(!process.wait().await.success());
}
}

0 comments on commit f9b5ba1

Please sign in to comment.