From 6fc6872e5de4b62b5b2f34a4398fb3bc0b61f20d Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 20 Jun 2023 12:05:40 +0100 Subject: [PATCH] refactor(api): [#197] make Axum implementation the default one --- .github/workflows/develop.yml | 2 +- src/bin/main.rs | 6 +- tests/e2e/config.rs | 4 +- tests/e2e/contexts/about/contract.rs | 15 ++ tests/e2e/contexts/category/contract.rs | 104 ++++++------ tests/e2e/contexts/root/contract.rs | 9 + tests/e2e/contexts/settings/contract.rs | 47 +++--- tests/e2e/contexts/tag/contract.rs | 109 ++++++------ tests/e2e/contexts/torrent/contract.rs | 210 ++++++++++++------------ tests/e2e/contexts/user/contract.rs | 86 +++++----- 10 files changed, 317 insertions(+), 275 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index b0a958d3..c613b039 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -32,4 +32,4 @@ jobs: - name: E2E Tests run: ./docker/bin/run-e2e-tests.sh env: - TORRUST_IDX_BACK_E2E_EXCLUDE_AXUM_IMPL: "true" + TORRUST_IDX_BACK_E2E_EXCLUDE_ACTIX_WEB_IMPL: "true" diff --git a/src/bin/main.rs b/src/bin/main.rs index 332c352d..46922a13 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -6,11 +6,7 @@ use torrust_index_backend::web::api::Implementation; async fn main() -> Result<(), std::io::Error> { let configuration = init_configuration().await; - // todo: we are migrating from actix-web to axum, so we need to keep both - // implementations for a while. For production we only use ActixWeb. - // Once the Axum implementation is finished and stable, we can switch to it - // and remove the ActixWeb implementation. - let api_implementation = Implementation::ActixWeb; + let api_implementation = Implementation::Axum; let app = app::run(configuration, &api_implementation).await; diff --git a/tests/e2e/config.rs b/tests/e2e/config.rs index abf056fd..ce168333 100644 --- a/tests/e2e/config.rs +++ b/tests/e2e/config.rs @@ -14,8 +14,8 @@ pub const ENV_VAR_E2E_SHARED: &str = "TORRUST_IDX_BACK_E2E_SHARED"; /// The whole `config.toml` file content. It has priority over the config file. pub const ENV_VAR_E2E_CONFIG: &str = "TORRUST_IDX_BACK_E2E_CONFIG"; -/// If present, E2E tests for new Axum implementation will not be executed -pub const ENV_VAR_E2E_EXCLUDE_AXUM_IMPL: &str = "TORRUST_IDX_BACK_E2E_EXCLUDE_AXUM_IMPL"; +/// If present, E2E tests for new `ActixWeb` implementation will not be executed +pub const ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL: &str = "TORRUST_IDX_BACK_E2E_EXCLUDE_ACTIX_WEB_IMPL"; // Default values diff --git a/tests/e2e/contexts/about/contract.rs b/tests/e2e/contexts/about/contract.rs index efe30227..7c3e84b2 100644 --- a/tests/e2e/contexts/about/contract.rs +++ b/tests/e2e/contexts/about/contract.rs @@ -1,14 +1,23 @@ //! API contract for `about` context. +use std::env; + use torrust_index_backend::web::api; use crate::common::asserts::{assert_response_title, assert_text_ok}; use crate::common::client::Client; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::environment::TestEnv; #[tokio::test] async fn it_should_load_the_about_page_with_information_about_the_api() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.about().await; @@ -21,6 +30,12 @@ async fn it_should_load_the_about_page_with_information_about_the_api() { async fn it_should_load_the_license_page_at_the_api_entrypoint() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.license().await; diff --git a/tests/e2e/contexts/category/contract.rs b/tests/e2e/contexts/category/contract.rs index 8200cf22..3187d89d 100644 --- a/tests/e2e/contexts/category/contract.rs +++ b/tests/e2e/contexts/category/contract.rs @@ -1,4 +1,6 @@ //! API contract for `category` context. +use std::env; + use torrust_index_backend::web::api; use crate::common::asserts::assert_json_ok_response; @@ -6,6 +8,7 @@ use crate::common::client::Client; use crate::common::contexts::category::fixtures::random_category_name; use crate::common::contexts::category::forms::{AddCategoryForm, DeleteCategoryForm}; use crate::common::contexts::category::responses::{AddedCategoryResponse, ListResponse}; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::category::steps::{add_category, add_random_category}; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -14,6 +17,12 @@ use crate::e2e::environment::TestEnv; async fn it_should_return_an_empty_category_list_when_there_are_no_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_categories().await; @@ -25,6 +34,12 @@ async fn it_should_return_an_empty_category_list_when_there_are_no_categories() async fn it_should_return_a_category_list() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); add_random_category(&env).await; @@ -47,6 +62,12 @@ async fn it_should_return_a_category_list() { async fn it_should_not_allow_adding_a_new_category_to_unauthenticated_users() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client @@ -64,6 +85,11 @@ async fn it_should_not_allow_adding_a_new_category_to_non_admins() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -83,6 +109,11 @@ async fn it_should_allow_admins_to_add_new_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -111,6 +142,11 @@ async fn it_should_allow_adding_empty_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if env.is_shared() { // This test cannot be run in a shared test env because it will fail // when the empty category already exits @@ -144,6 +180,11 @@ async fn it_should_not_allow_adding_duplicated_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let added_category_name = add_random_category(&env).await; // Try to add the same category again @@ -156,6 +197,11 @@ async fn it_should_allow_admins_to_delete_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -182,6 +228,11 @@ async fn it_should_not_allow_non_admins_to_delete_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let added_category_name = add_random_category(&env).await; let logged_in_non_admin = new_logged_in_user(&env).await; @@ -201,6 +252,12 @@ async fn it_should_not_allow_non_admins_to_delete_categories() { async fn it_should_not_allow_guests_to_delete_categories() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let added_category_name = add_random_category(&env).await; @@ -216,7 +273,6 @@ async fn it_should_not_allow_guests_to_delete_categories() { } mod with_axum_implementation { - use std::env; use torrust_index_backend::web::api; @@ -226,7 +282,6 @@ mod with_axum_implementation { use crate::common::contexts::category::fixtures::random_category_name; use crate::common::contexts::category::forms::{AddCategoryForm, DeleteCategoryForm}; use crate::common::contexts::category::responses::ListResponse; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::category::steps::{add_category, add_random_category}; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -248,11 +303,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); add_random_category(&env).await; @@ -276,11 +326,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client @@ -298,11 +343,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -322,11 +362,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -356,11 +391,6 @@ mod with_axum_implementation { return; } - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -381,11 +411,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let added_category_name = add_random_category(&env).await; // Try to add the same category again @@ -399,11 +424,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -424,11 +444,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let added_category_name = add_random_category(&env).await; let logged_in_non_admin = new_logged_in_user(&env).await; @@ -449,11 +464,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let added_category_name = add_random_category(&env).await; diff --git a/tests/e2e/contexts/root/contract.rs b/tests/e2e/contexts/root/contract.rs index ab5269b4..bf7bd754 100644 --- a/tests/e2e/contexts/root/contract.rs +++ b/tests/e2e/contexts/root/contract.rs @@ -1,14 +1,23 @@ //! API contract for `root` context. +use std::env; + use torrust_index_backend::web::api; use crate::common::asserts::{assert_response_title, assert_text_ok}; use crate::common::client::Client; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::environment::TestEnv; #[tokio::test] async fn it_should_load_the_about_page_at_the_api_entrypoint() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.root().await; diff --git a/tests/e2e/contexts/settings/contract.rs b/tests/e2e/contexts/settings/contract.rs index 97e6082e..d82d45a3 100644 --- a/tests/e2e/contexts/settings/contract.rs +++ b/tests/e2e/contexts/settings/contract.rs @@ -1,7 +1,10 @@ +use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::settings::responses::{AllSettingsResponse, Public, PublicSettingsResponse, SiteNameResponse}; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::user::steps::new_logged_in_admin; use crate::e2e::environment::TestEnv; @@ -9,6 +12,12 @@ use crate::e2e::environment::TestEnv; async fn it_should_allow_guests_to_get_the_public_settings() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_public_settings().await; @@ -34,6 +43,12 @@ async fn it_should_allow_guests_to_get_the_public_settings() { async fn it_should_allow_guests_to_get_the_site_name() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_site_name().await; @@ -52,6 +67,11 @@ async fn it_should_allow_admins_to_get_all_the_settings() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -71,6 +91,11 @@ async fn it_should_allow_admins_to_update_all_the_settings() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.is_isolated() { // This test can't be executed in a non-isolated environment because // it will change the settings for all the other tests. @@ -96,14 +121,12 @@ async fn it_should_allow_admins_to_update_all_the_settings() { } mod with_axum_implementation { - use std::env; use torrust_index_backend::web::api; use crate::common::asserts::assert_json_ok_response; use crate::common::client::Client; use crate::common::contexts::settings::responses::{AllSettingsResponse, Public, PublicSettingsResponse, SiteNameResponse}; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::user::steps::new_logged_in_admin; use crate::e2e::environment::TestEnv; @@ -112,11 +135,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_public_settings().await; @@ -142,11 +160,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_site_name().await; @@ -163,11 +176,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -185,11 +193,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.is_isolated() { // This test can't be executed in a non-isolated environment because // it will change the settings for all the other tests. diff --git a/tests/e2e/contexts/tag/contract.rs b/tests/e2e/contexts/tag/contract.rs index 9dd8ff15..711b1c0a 100644 --- a/tests/e2e/contexts/tag/contract.rs +++ b/tests/e2e/contexts/tag/contract.rs @@ -1,4 +1,6 @@ //! API contract for `tag` context. +use std::env; + use torrust_index_backend::web::api; use crate::common::asserts::assert_json_ok_response; @@ -6,6 +8,7 @@ use crate::common::client::Client; use crate::common::contexts::tag::fixtures::random_tag_name; use crate::common::contexts::tag::forms::{AddTagForm, DeleteTagForm}; use crate::common::contexts::tag::responses::{AddedTagResponse, DeletedTagResponse, ListResponse}; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::tag::steps::{add_random_tag, add_tag}; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -14,6 +17,12 @@ use crate::e2e::environment::TestEnv; async fn it_should_return_an_empty_tag_list_when_there_are_no_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_tags().await; @@ -25,6 +34,12 @@ async fn it_should_return_an_empty_tag_list_when_there_are_no_tags() { async fn it_should_return_a_tag_list() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); // Add a tag @@ -50,6 +65,12 @@ async fn it_should_return_a_tag_list() { async fn it_should_not_allow_adding_a_new_tag_to_unauthenticated_users() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client @@ -66,6 +87,11 @@ async fn it_should_not_allow_adding_a_new_tag_to_non_admins() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -84,6 +110,11 @@ async fn it_should_allow_admins_to_add_new_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -111,6 +142,11 @@ async fn it_should_allow_adding_duplicated_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + // Add a tag let random_tag_name = random_tag_name(); let response = add_tag(&random_tag_name, &env).await; @@ -128,6 +164,11 @@ async fn it_should_allow_adding_a_tag_with_an_empty_name() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let empty_tag_name = String::new(); let response = add_tag(&empty_tag_name, &env).await; assert_eq!(response.status, 200); @@ -138,6 +179,11 @@ async fn it_should_allow_admins_to_delete_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -159,6 +205,11 @@ async fn it_should_not_allow_non_admins_to_delete_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_non_admin.token); @@ -173,6 +224,12 @@ async fn it_should_not_allow_non_admins_to_delete_tags() { async fn it_should_not_allow_guests_to_delete_tags() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let (tag_id, _tag_name) = add_random_tag(&env).await; @@ -183,7 +240,6 @@ async fn it_should_not_allow_guests_to_delete_tags() { } mod with_axum_implementation { - use std::env; use torrust_index_backend::web::api; @@ -193,7 +249,6 @@ mod with_axum_implementation { use crate::common::contexts::tag::fixtures::random_tag_name; use crate::common::contexts::tag::forms::{AddTagForm, DeleteTagForm}; use crate::common::contexts::tag::responses::ListResponse; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::tag::steps::{add_random_tag, add_tag}; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -203,11 +258,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client.get_tags().await; @@ -220,11 +270,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); // Add a tag @@ -251,11 +296,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let response = client @@ -272,11 +312,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -295,11 +330,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -321,11 +351,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - // Add a tag let random_tag_name = random_tag_name(); let response = add_tag(&random_tag_name, &env).await; @@ -343,11 +368,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let empty_tag_name = String::new(); let response = add_tag(&empty_tag_name, &env).await; assert_eq!(response.status, 200); @@ -358,11 +378,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -378,11 +393,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_non_admin.token); @@ -398,11 +408,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let (tag_id, _tag_name) = add_random_tag(&env).await; diff --git a/tests/e2e/contexts/torrent/contract.rs b/tests/e2e/contexts/torrent/contract.rs index c14acf67..52c084fe 100644 --- a/tests/e2e/contexts/torrent/contract.rs +++ b/tests/e2e/contexts/torrent/contract.rs @@ -15,6 +15,8 @@ Get torrent info: */ mod for_guests { + use std::env; + use torrust_index_backend::utils::parse_torrent::decode_torrent; use torrust_index_backend::web::api; @@ -26,6 +28,7 @@ mod for_guests { Category, File, TorrentDetails, TorrentDetailsResponse, TorrentListResponse, }; use crate::common::http::{Query, QueryParam}; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::torrent::asserts::expected_torrent; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; @@ -36,6 +39,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -59,6 +67,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -89,6 +102,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -124,6 +142,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -155,6 +178,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -218,6 +246,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -243,6 +276,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -263,6 +301,11 @@ mod for_guests { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -281,6 +324,8 @@ mod for_guests { mod for_authenticated_users { + use std::env; + use torrust_index_backend::utils::parse_torrent::decode_torrent; use torrust_index_backend::web::api; @@ -288,6 +333,7 @@ mod for_authenticated_users { use crate::common::contexts::torrent::fixtures::random_torrent; use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; use crate::common::contexts::torrent::responses::UploadedTorrentResponse; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::torrent::asserts::{build_announce_url, get_user_tracker_key}; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; @@ -298,6 +344,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -327,6 +378,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let uploader = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token); @@ -346,6 +402,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -375,6 +436,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -405,6 +471,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -437,10 +508,13 @@ mod for_authenticated_users { } mod and_non_admins { + use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; use crate::e2e::environment::TestEnv; @@ -450,6 +524,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -470,6 +549,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -501,11 +585,14 @@ mod for_authenticated_users { } mod and_torrent_owners { + use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; use crate::common::contexts::torrent::responses::UpdatedTorrentResponse; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; use crate::e2e::environment::TestEnv; @@ -515,6 +602,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -549,11 +641,14 @@ mod for_authenticated_users { } mod and_admins { + use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; use crate::common::contexts::torrent::responses::{DeletedTorrentResponse, UpdatedTorrentResponse}; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -563,6 +658,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -587,6 +687,11 @@ mod for_authenticated_users { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -626,8 +731,6 @@ mod with_axum_implementation { mod for_guests { - use std::env; - use torrust_index_backend::utils::parse_torrent::decode_torrent; use torrust_index_backend::web::api; @@ -639,7 +742,6 @@ mod with_axum_implementation { Category, File, TorrentDetails, TorrentDetailsResponse, TorrentListResponse, }; use crate::common::http::{Query, QueryParam}; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::torrent::asserts::expected_torrent; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; @@ -650,11 +752,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -678,11 +775,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -713,11 +805,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -753,11 +840,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -789,11 +871,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -857,11 +934,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -887,11 +959,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -912,11 +979,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -935,8 +997,6 @@ mod with_axum_implementation { mod for_authenticated_users { - use std::env; - use torrust_index_backend::utils::parse_torrent::decode_torrent; use torrust_index_backend::web::api; @@ -945,7 +1005,6 @@ mod with_axum_implementation { use crate::common::contexts::torrent::fixtures::random_torrent; use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; use crate::common::contexts::torrent::responses::UploadedTorrentResponse; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::torrent::asserts::{build_announce_url, get_user_tracker_key}; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; @@ -956,11 +1015,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -990,11 +1044,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let uploader = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token); @@ -1014,11 +1063,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1047,11 +1091,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1082,11 +1121,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1120,13 +1154,10 @@ mod with_axum_implementation { mod and_non_admins { - use std::env; - use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; use crate::e2e::environment::TestEnv; @@ -1136,11 +1167,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1161,11 +1187,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1198,14 +1219,11 @@ mod with_axum_implementation { mod and_torrent_owners { - use std::env; - use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; use crate::common::contexts::torrent::responses::UpdatedTorrentResponse; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::new_logged_in_user; use crate::e2e::environment::TestEnv; @@ -1215,11 +1233,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1255,14 +1268,11 @@ mod with_axum_implementation { mod and_admins { - use std::env; - use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::torrent::forms::UpdateTorrentFrom; use crate::common::contexts::torrent::responses::{DeletedTorrentResponse, UpdatedTorrentResponse}; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user}; use crate::e2e::environment::TestEnv; @@ -1272,11 +1282,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; @@ -1301,11 +1306,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - if !env.provides_a_tracker() { println!("test skipped. It requires a tracker to be running."); return; diff --git a/tests/e2e/contexts/user/contract.rs b/tests/e2e/contexts/user/contract.rs index 73eff810..17732da9 100644 --- a/tests/e2e/contexts/user/contract.rs +++ b/tests/e2e/contexts/user/contract.rs @@ -1,4 +1,6 @@ //! API contract for `user` context. +use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; @@ -7,6 +9,7 @@ use crate::common::contexts::user::forms::{LoginForm, TokenRenewalForm, TokenVer use crate::common::contexts::user::responses::{ SuccessfulLoginResponse, TokenRenewalData, TokenRenewalResponse, TokenVerifiedResponse, }; +use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::user::steps::{new_logged_in_user, new_registered_user}; use crate::e2e::environment::TestEnv; @@ -42,6 +45,12 @@ the mailcatcher API. async fn it_should_allow_a_guest_user_to_register() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let form = random_user_registration_form(); @@ -59,6 +68,12 @@ async fn it_should_allow_a_guest_user_to_register() { async fn it_should_allow_a_registered_user_to_login() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let registered_user = new_registered_user(&env).await; @@ -84,6 +99,12 @@ async fn it_should_allow_a_registered_user_to_login() { async fn it_should_allow_a_logged_in_user_to_verify_an_authentication_token() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let logged_in_user = new_logged_in_user(&env).await; @@ -108,6 +129,11 @@ async fn it_should_not_allow_a_logged_in_user_to_renew_an_authentication_token_w let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_user = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_user.token); @@ -134,11 +160,14 @@ async fn it_should_not_allow_a_logged_in_user_to_renew_an_authentication_token_w } mod banned_user_list { + use std::env; + use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::user::forms::Username; use crate::common::contexts::user::responses::BannedUserResponse; + use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user, new_registered_user}; use crate::e2e::environment::TestEnv; @@ -147,6 +176,11 @@ mod banned_user_list { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -168,6 +202,11 @@ mod banned_user_list { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -182,6 +221,12 @@ mod banned_user_list { async fn it_should_not_allow_a_guest_to_ban_a_user() { let mut env = TestEnv::new(); env.start(api::Implementation::ActixWeb).await; + + if env::var(ENV_VAR_E2E_EXCLUDE_ACTIX_WEB_IMPL).is_ok() { + println!("Skipped"); + return; + } + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let registered_user = new_registered_user(&env).await; @@ -195,14 +240,12 @@ mod banned_user_list { mod with_axum_implementation { mod registration { - use std::env; use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::user::asserts::assert_added_user_response; use crate::common::contexts::user::fixtures::random_user_registration_form; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::environment::TestEnv; #[tokio::test] @@ -210,11 +253,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let form = random_user_registration_form(); @@ -226,7 +264,6 @@ mod with_axum_implementation { } mod authentication { - use std::env; use torrust_index_backend::web::api; @@ -235,7 +272,6 @@ mod with_axum_implementation { assert_successful_login_response, assert_token_renewal_response, assert_token_verified_response, }; use crate::common::contexts::user::forms::{LoginForm, TokenRenewalForm, TokenVerificationForm}; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::user::steps::{new_logged_in_user, new_registered_user}; use crate::e2e::environment::TestEnv; @@ -244,11 +280,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let registered_user = new_registered_user(&env).await; @@ -268,11 +299,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let logged_in_user = new_logged_in_user(&env).await; @@ -292,11 +318,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_user = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_user.token); @@ -312,14 +333,12 @@ mod with_axum_implementation { } mod banned_user_list { - use std::env; use torrust_index_backend::web::api; use crate::common::client::Client; use crate::common::contexts::user::asserts::assert_banned_user_response; use crate::common::contexts::user::forms::Username; - use crate::e2e::config::ENV_VAR_E2E_EXCLUDE_AXUM_IMPL; use crate::e2e::contexts::user::steps::{new_logged_in_admin, new_logged_in_user, new_registered_user}; use crate::e2e::environment::TestEnv; @@ -328,11 +347,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -349,11 +363,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let logged_non_admin = new_logged_in_user(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_non_admin.token); @@ -370,11 +379,6 @@ mod with_axum_implementation { let mut env = TestEnv::new(); env.start(api::Implementation::Axum).await; - if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() { - println!("Skipped"); - return; - } - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let registered_user = new_registered_user(&env).await;