From b6e94ad58c6d8c56106a445c439588074c022d26 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Tue, 7 Dec 2021 08:44:46 +0100 Subject: [PATCH] Modularize step defs --- Cargo.toml | 2 +- Makefile | 2 +- tests/features_runner.rs | 14 +++++++++ tests/step_defs/integration/abi.rs | 29 +++++++++++++++++++ .../integration/algod.rs} | 5 ---- tests/step_defs/integration/mod.rs | 2 ++ tests/step_defs/mod.rs | 1 + 7 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 tests/features_runner.rs create mode 100644 tests/step_defs/integration/abi.rs rename tests/{cucumber.rs => step_defs/integration/algod.rs} (95%) create mode 100644 tests/step_defs/integration/mod.rs create mode 100644 tests/step_defs/mod.rs diff --git a/Cargo.toml b/Cargo.toml index c2284cef..80752437 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,5 +45,5 @@ native = ["algonaut_client/native"] rustls = ["algonaut_client/rustls"] [[test]] -name = "cucumber" +name = "features_runner" harness = false # Allows Cucumber to print output instead of libtest diff --git a/Makefile b/Makefile index 19c9600d..e96b459e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ integration: - cargo test --test cucumber -- + cargo test --test features_runner -- docker-test: ./tests/docker/run_docker.sh diff --git a/tests/features_runner.rs b/tests/features_runner.rs new file mode 100644 index 00000000..04d0f960 --- /dev/null +++ b/tests/features_runner.rs @@ -0,0 +1,14 @@ +use cucumber::WorldInit; +use step_defs::integration; + +mod step_defs; + +#[tokio::main] +async fn main() { + integration::algod::World::run(integration_path("algod")).await; + integration::abi::World::run(integration_path("abi")).await; +} + +fn integration_path(feature_name: &str) -> String { + format!("tests/features/integration/{}.feature", feature_name) +} diff --git a/tests/step_defs/integration/abi.rs b/tests/step_defs/integration/abi.rs new file mode 100644 index 00000000..75c07c23 --- /dev/null +++ b/tests/step_defs/integration/abi.rs @@ -0,0 +1,29 @@ +use algonaut::algod::v2::Algod; +use algonaut::algod::AlgodBuilder; +use async_trait::async_trait; +use cucumber::{given, WorldInit}; +use std::convert::Infallible; + +#[derive(Default, Debug, WorldInit)] +pub struct World { + algod: Option, +} + +#[async_trait(?Send)] +impl cucumber::World for World { + type Error = Infallible; + + async fn new() -> Result { + Ok(Self::default()) + } +} + +#[given(expr = "an algod v2 client")] +async fn an_algod_v2_client(w: &mut World) { + let algod = AlgodBuilder::new() + .bind("http://localhost:60000") + .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .build_v2() + .unwrap(); + w.algod = Some(algod) +} diff --git a/tests/cucumber.rs b/tests/step_defs/integration/algod.rs similarity index 95% rename from tests/cucumber.rs rename to tests/step_defs/integration/algod.rs index 494824cf..8b77ff66 100644 --- a/tests/cucumber.rs +++ b/tests/step_defs/integration/algod.rs @@ -60,8 +60,3 @@ async fn i_can_get_the_block_info(w: &mut World) { let last_round = w.last_round.unwrap(); algod_client.block(Round(last_round)).await.unwrap(); } - -#[tokio::main] -async fn main() { - World::run("tests/features/integration").await; -} diff --git a/tests/step_defs/integration/mod.rs b/tests/step_defs/integration/mod.rs new file mode 100644 index 00000000..f6bb8748 --- /dev/null +++ b/tests/step_defs/integration/mod.rs @@ -0,0 +1,2 @@ +pub mod abi; +pub mod algod; diff --git a/tests/step_defs/mod.rs b/tests/step_defs/mod.rs new file mode 100644 index 00000000..5155b774 --- /dev/null +++ b/tests/step_defs/mod.rs @@ -0,0 +1 @@ +pub mod integration;