From de60a24602a9d42ae6cc2e188ec025ecb0e69086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Thu, 7 Jul 2022 11:26:49 +0200 Subject: [PATCH] Remove __test feature --- .github/workflows/ci.yml | 2 +- crates/matrix-sdk/Cargo.toml | 3 -- crates/matrix-sdk/src/client/builder.rs | 4 +- crates/matrix-sdk/src/client/mod.rs | 38 +++++++++++++- crates/matrix-sdk/tests/integration/client.rs | 51 ------------------- xtask/src/ci.rs | 2 +- 6 files changed, 41 insertions(+), 59 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 537f3426b..fb813b1a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,7 +127,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: nextest - args: run --workspace --features __test + args: run --workspace - name: Test documentation uses: actions-rs/cargo@v1 diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index d3ab05d32..c6f87f915 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -55,9 +55,6 @@ docsrs = [ "image-proc", ] -# This is an internal feature only used for tests -__test = [] - [dependencies] anyhow = { version = "1.0.57", optional = true } anymap2 = "0.13.0" diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index 34443d0e3..41705380a 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -343,12 +343,12 @@ impl ClientBuilder { } fn homeserver_from_name(server_name: &ServerName) -> String { - #[cfg(not(any(test, feature = "__test")))] + #[cfg(not(test))] return format!("https://{}", server_name); // Mockito only knows how to test http endpoints: // https://github.com/lipanski/mockito/issues/127 - #[cfg(any(test, feature = "__test"))] + #[cfg(test)] return format!("http://{}", server_name); } diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 19fd69b14..56d740b91 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -2200,7 +2200,7 @@ pub(crate) mod tests { wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); use mockito::{mock, Matcher}; - use ruma::{api::MatrixVersion, device_id, room_id, user_id}; + use ruma::{api::MatrixVersion, device_id, room_id, user_id, UserId}; use url::Url; use super::{Client, ClientBuilder, Session}; @@ -2249,6 +2249,42 @@ pub(crate) mod tests { // assert_eq!(1, ignored_users.len()) } + #[async_test] + async fn successful_discovery() { + let server_url = mockito::server_url(); + let domain = server_url.strip_prefix("http://").unwrap(); + let alice = UserId::parse("@alice:".to_owned() + domain).unwrap(); + + let _m_well_known = mock("GET", "/.well-known/matrix/client") + .with_status(200) + .with_body( + test_json::WELL_KNOWN.to_string().replace("HOMESERVER_URL", server_url.as_ref()), + ) + .create(); + + let _m_versions = mock("GET", "/_matrix/client/versions") + .with_status(200) + .with_body(test_json::VERSIONS.to_string()) + .create(); + let client = Client::builder().user_id(&alice).build().await.unwrap(); + + assert_eq!(client.homeserver().await, Url::parse(server_url.as_ref()).unwrap()); + } + + #[async_test] + async fn discovery_broken_server() { + let server_url = mockito::server_url(); + let domain = server_url.strip_prefix("http://").unwrap(); + let alice = UserId::parse("@alice:".to_owned() + domain).unwrap(); + + let _m = mock("GET", "/.well-known/matrix/client").with_status(404).create(); + + assert!( + Client::builder().user_id(&alice).build().await.is_err(), + "Creating a client from a user ID should fail when the .well-known request fails." + ); + } + #[async_test] async fn room_creation() { let client = logged_in_client().await; diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index be6c27c63..c7c3a7d52 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -3,8 +3,6 @@ use std::{collections::BTreeMap, str::FromStr, time::Duration}; -#[cfg(feature = "__test")] -use matrix_sdk::{config::RequestConfig, Client}; use matrix_sdk::{ config::SyncSettings, media::{MediaFormat, MediaRequest, MediaThumbnailSize}, @@ -12,8 +10,6 @@ use matrix_sdk::{ }; use matrix_sdk_test::{async_test, test_json}; use mockito::{mock, Matcher}; -#[cfg(feature = "__test")] -use ruma::UserId; use ruma::{ api::{ client::{ @@ -48,53 +44,6 @@ async fn set_homeserver() { assert_eq!(client.homeserver().await, homeserver); } -#[cfg(feature = "__test")] -#[async_test] -async fn successful_discovery() { - let server_url = mockito::server_url(); - let domain = server_url.strip_prefix("http://").unwrap(); - let alice = UserId::parse("@alice:".to_owned() + domain).unwrap(); - - let _m_well_known = mock("GET", "/.well-known/matrix/client") - .with_status(200) - .with_body(test_json::WELL_KNOWN.to_string().replace("HOMESERVER_URL", server_url.as_ref())) - .create(); - - let _m_versions = mock("GET", "/_matrix/client/versions") - .with_status(200) - .with_body(test_json::VERSIONS.to_string()) - .create(); - - let client = Client::builder() - .request_config(RequestConfig::new().disable_retry()) - .user_id(&alice) - .build() - .await - .unwrap(); - - assert_eq!(client.homeserver().await, Url::parse(server_url.as_ref()).unwrap()); -} - -#[cfg(feature = "__test")] -#[async_test] -async fn discovery_broken_server() { - let server_url = mockito::server_url(); - let domain = server_url.strip_prefix("http://").unwrap(); - let alice = UserId::parse("@alice:".to_owned() + domain).unwrap(); - - let _m = mock("GET", "/.well-known/matrix/client").with_status(404).create(); - - assert!( - Client::builder() - .request_config(RequestConfig::new().disable_retry()) - .user_id(&alice) - .build() - .await - .is_err(), - "Creating a client from a user ID should fail when the .well-known request fails." - ); -} - #[async_test] async fn login() { let homeserver = Url::from_str(&mockito::server_url()).unwrap(); diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 6ee336840..c3a1df7c7 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -154,7 +154,7 @@ fn run_feature_tests(cmd: Option) -> Result<()> { ]); let run = |arg_set: &str| { - cmd!("rustup run stable cargo nextest run -p matrix-sdk --features __test") + cmd!("rustup run stable cargo nextest run -p matrix-sdk") .args(arg_set.split_whitespace()) .run()?; cmd!("rustup run stable cargo test --doc -p matrix-sdk")