Skip to content

Commit 0f974bc

Browse files
committed
refactor: cargo test
The default rust `test` utilities are quite powerful. This PR leverages them in order to: - natively use multiprocessing to run tests in parallel - have comprehensive `pass` and `error` logs Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
1 parent c5c7c85 commit 0f974bc

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

tools/e2e_test/src/image_credentials/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::suite::client;
2525
pub mod mutations;
2626
pub mod queries;
2727

28-
pub async fn run_test(client: client::EdgehogClient) -> eyre::Result<()> {
28+
pub async fn test_image_credentials(client: client::EdgehogClient) -> eyre::Result<()> {
2929
let username = Alphabetic.sample_string(&mut rand::rng(), 5);
3030
let label = Alphabetic.sample_string(&mut rand::rng(), 5);
3131
let password = Alphabetic.sample_string(&mut rand::rng(), 10);
@@ -64,7 +64,5 @@ pub async fn run_test(client: client::EdgehogClient) -> eyre::Result<()> {
6464
assert_eq!(image_credentials.username, username);
6565
assert_eq!(image_credentials.label, label);
6666

67-
println!("[ PASSED ] image credentials tests");
68-
6967
Ok(())
7068
}

tools/e2e_test/src/main.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,32 @@
1919
mod image_credentials;
2020
mod suite;
2121

22-
use clap::Parser;
23-
use suite::client::EdgehogClient;
24-
use suite::config::Config;
25-
2622
#[tokio::main]
2723
async fn main() -> eyre::Result<()> {
28-
let config = Config::parse();
29-
let client = EdgehogClient::create(&config)?;
30-
image_credentials::run_test(client).await
24+
Ok(())
25+
}
26+
27+
#[cfg(test)]
28+
mod test {
29+
use super::*;
30+
31+
use suite::client::EdgehogClient;
32+
use suite::config::Config;
33+
34+
fn test_config() -> Config {
35+
Config {
36+
hostname: "api.edgehog.localhost".to_string(),
37+
scheme: "http".to_string(),
38+
bearer: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJlX3RnYSI6IioiLCJpYXQiOjE3Mzg5NDgzODh9.TTiXYs1LucAnS_6RGp7pWg-S30NSt7eqL7lU8BzT5BWlHctk7NYZwC6lftA6WeEb1HKEJfPoUqWeOeZ6oYA0AA".to_string(),
39+
tenant: "test".to_string()
40+
}
41+
}
42+
43+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
44+
async fn image_credentials() -> eyre::Result<()> {
45+
let config = test_config();
46+
47+
let client = EdgehogClient::create(&config)?;
48+
image_credentials::test_image_credentials(client).await
49+
}
3150
}

0 commit comments

Comments
 (0)