diff --git a/crates/matrix-sdk/src/account.rs b/crates/matrix-sdk/src/account.rs index 89c82d1c6..5d150f1d1 100644 --- a/crates/matrix-sdk/src/account.rs +++ b/crates/matrix-sdk/src/account.rs @@ -1177,7 +1177,7 @@ mod tests { #[async_test] async fn test_dont_ignore_oneself() { - let client = MockClientBuilder::new("https://example.org".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; // It's forbidden to ignore the logged-in user. assert_matches!( diff --git a/crates/matrix-sdk/src/authentication/oauth/cross_process.rs b/crates/matrix-sdk/src/authentication/oauth/cross_process.rs index f5e8c14ac..53da17838 100644 --- a/crates/matrix-sdk/src/authentication/oauth/cross_process.rs +++ b/crates/matrix-sdk/src/authentication/oauth/cross_process.rs @@ -269,11 +269,7 @@ mod tests { // Create a client that will use sqlite databases. let tmp_dir = tempfile::tempdir()?; - let client = MockClientBuilder::new("https://example.org".to_owned()) - .sqlite_store(&tmp_dir) - .unlogged() - .build() - .await; + let client = MockClientBuilder::new(None).sqlite_store(&tmp_dir).unlogged().build().await; let tokens = mock_session_tokens_with_refresh(); diff --git a/crates/matrix-sdk/src/authentication/oauth/tests.rs b/crates/matrix-sdk/src/authentication/oauth/tests.rs index 51687e8d2..b1d2050d8 100644 --- a/crates/matrix-sdk/src/authentication/oauth/tests.rs +++ b/crates/matrix-sdk/src/authentication/oauth/tests.rs @@ -483,7 +483,7 @@ async fn test_finish_login() -> anyhow::Result<()> { #[async_test] async fn test_oauth_session() -> anyhow::Result<()> { - let client = MockClientBuilder::new("https://example.org".to_owned()).unlogged().build().await; + let client = MockClientBuilder::new(None).unlogged().build().await; let oauth = client.oauth(); let tokens = mock_session_tokens_with_refresh(); diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 3857e3d04..a46f8b3dd 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -2010,7 +2010,7 @@ mod timed_tests { let event_cache_store = Arc::new(MemoryStore::new()); - let client = MockClientBuilder::new("http://localhost".to_owned()) + let client = MockClientBuilder::new(None) .store_config( StoreConfig::new("hodlor".to_owned()).event_cache_store(event_cache_store.clone()), ) @@ -2084,7 +2084,7 @@ mod timed_tests { let event_cache_store = Arc::new(MemoryStore::new()); - let client = MockClientBuilder::new("http://localhost".to_owned()) + let client = MockClientBuilder::new(None) .store_config( StoreConfig::new("hodlor".to_owned()).event_cache_store(event_cache_store.clone()), ) @@ -2223,7 +2223,7 @@ mod timed_tests { .await .unwrap(); - let client = MockClientBuilder::new("http://localhost".to_owned()) + let client = MockClientBuilder::new(None) .store_config( StoreConfig::new("hodlor".to_owned()).event_cache_store(event_cache_store.clone()), ) @@ -2361,7 +2361,7 @@ mod timed_tests { .await .unwrap(); - let client = MockClientBuilder::new("http://localhost".to_owned()) + let client = MockClientBuilder::new(None) .store_config( StoreConfig::new("hodlor".to_owned()).event_cache_store(event_cache_store.clone()), ) @@ -2482,7 +2482,7 @@ mod timed_tests { .await .unwrap(); - let client = MockClientBuilder::new("http://localhost".to_owned()) + let client = MockClientBuilder::new(None) .store_config( StoreConfig::new("holder".to_owned()).event_cache_store(event_cache_store.clone()), ) @@ -2516,7 +2516,7 @@ mod timed_tests { async fn test_no_useless_gaps() { let room_id = room_id!("!galette:saucisse.bzh"); - let client = MockClientBuilder::new("http://localhost".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; let event_cache = client.event_cache(); event_cache.subscribe().unwrap(); @@ -2638,7 +2638,7 @@ mod timed_tests { async fn test_shrink_to_last_chunk() { let room_id = room_id!("!galette:saucisse.bzh"); - let client = MockClientBuilder::new("http://localhost".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; let f = EventFactory::new().room(room_id); @@ -2747,7 +2747,7 @@ mod timed_tests { async fn test_room_ordering() { let room_id = room_id!("!galette:saucisse.bzh"); - let client = MockClientBuilder::new("http://localhost".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; let f = EventFactory::new().room(room_id).sender(*ALICE); @@ -2882,7 +2882,7 @@ mod timed_tests { async fn test_auto_shrink_after_all_subscribers_are_gone() { let room_id = room_id!("!galette:saucisse.bzh"); - let client = MockClientBuilder::new("http://localhost".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; let f = EventFactory::new().room(room_id); @@ -2993,7 +2993,7 @@ mod timed_tests { async fn test_rfind_event_in_memory_by() { let user_id = user_id!("@mnt_io:matrix.org"); let room_id = room_id!("!raclette:patate.ch"); - let client = MockClientBuilder::new("http://localhost".to_owned()).build().await; + let client = MockClientBuilder::new(None).build().await; let event_factory = EventFactory::new().room(room_id); diff --git a/crates/matrix-sdk/src/test_utils/client.rs b/crates/matrix-sdk/src/test_utils/client.rs index 6cf230d15..e787b6aad 100644 --- a/crates/matrix-sdk/src/test_utils/client.rs +++ b/crates/matrix-sdk/src/test_utils/client.rs @@ -36,10 +36,13 @@ impl MockClientBuilder { /// Create a new [`MockClientBuilder`] connected to the given homeserver, /// using Matrix V1.12, and which will not attempt any network retry (by /// default). - pub(crate) fn new(homeserver: String) -> Self { + /// + /// If no homeserver is provided, `http://localhost` is used as a homeserver. + pub(crate) fn new(homeserver: Option<&str>) -> Self { + let homeserver = homeserver.unwrap_or("http://localhost"); + let default_builder = Client::builder() - .homeserver_url(&homeserver) - .server_versions([MatrixVersion::V1_12]) + .homeserver_url(homeserver) .request_config(RequestConfig::new().disable_retry()); Self { diff --git a/crates/matrix-sdk/src/test_utils/mocks/encryption.rs b/crates/matrix-sdk/src/test_utils/mocks/encryption.rs index f4cf4fb90..da9dcfcbc 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/encryption.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/encryption.rs @@ -96,7 +96,7 @@ impl MatrixMockServer { mappings.insert(auth_string, user_id.to_owned()); } - MockClientBuilder::new(self.server.uri()).logged_in_with_token( + MockClientBuilder::new(Some(&self.server.uri())).logged_in_with_token( access_token, user_id.to_owned(), device_id.to_owned(), diff --git a/crates/matrix-sdk/src/test_utils/mocks/mod.rs b/crates/matrix-sdk/src/test_utils/mocks/mod.rs index a84b97a1b..9ba9860dc 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/mod.rs @@ -180,7 +180,7 @@ impl MatrixMockServer { /// Creates a new [`MockClientBuilder`] configured to use this server, /// preconfigured with a session expected by the server endpoints. pub fn client_builder(&self) -> MockClientBuilder { - MockClientBuilder::new(self.server.uri()) + MockClientBuilder::new(Some(&self.server.uri())) } /// Return the underlying [`wiremock`] server.