Remove __test feature

This commit is contained in:
Kévin Commaille
2022-07-07 11:26:49 +02:00
parent dd6a902240
commit de60a24602
6 changed files with 41 additions and 59 deletions
+1 -1
View File
@@ -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
-3
View File
@@ -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"
+2 -2
View File
@@ -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);
}
+37 -1
View File
@@ -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;
@@ -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();
+1 -1
View File
@@ -154,7 +154,7 @@ fn run_feature_tests(cmd: Option<FeatureSet>) -> 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")