forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds e2e tests for verify-config cli. (metalbear-co#1998)
* Adds e2e tests for verify-config cli. * improve tests // use dedicated config file * changelog * docs * notices to not modify tests
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 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
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. |
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,11 @@ | ||
{ | ||
"feature": { | ||
"network": { | ||
"incoming": "mirror", | ||
"outgoing": true | ||
}, | ||
"fs": "read", | ||
"env": true | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ mod pause; | |
mod target; | ||
mod targetless; | ||
mod traffic; | ||
mod verify_config; | ||
|
||
pub mod utils; |
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,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()); | ||
} | ||
} |