client-api: Move some tests behind feature flags
This commit is contained in:
parent
22d9f30c67
commit
a310ccc318
@ -76,11 +76,10 @@ mod tests {
|
|||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_api::OutgoingRequest as _;
|
use ruma_api::OutgoingRequest as _;
|
||||||
|
|
||||||
use super::{Request, Response};
|
#[cfg(feature = "client")]
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn construct_request_from_refs() {
|
fn construct_request_from_refs() {
|
||||||
let req: http::Request<Vec<u8>> = Request {
|
let req: http::Request<Vec<u8>> = super::Request {
|
||||||
limit: Some(uint!(10)),
|
limit: Some(uint!(10)),
|
||||||
since: Some("hello"),
|
since: Some("hello"),
|
||||||
server: Some("address".try_into().unwrap()),
|
server: Some("address".try_into().unwrap()),
|
||||||
@ -97,9 +96,10 @@ mod tests {
|
|||||||
assert!(query.contains("server=address"));
|
assert!(query.contains("server=address"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
#[test]
|
#[test]
|
||||||
fn construct_response_from_refs() {
|
fn construct_response_from_refs() {
|
||||||
let res: http::Response<Vec<u8>> = Response {
|
let res: http::Response<Vec<u8>> = super::Response {
|
||||||
chunk: vec![],
|
chunk: vec![],
|
||||||
next_batch: Some("next_batch_token".into()),
|
next_batch: Some("next_batch_token".into()),
|
||||||
prev_batch: Some("prev_batch_token".into()),
|
prev_batch: Some("prev_batch_token".into()),
|
||||||
|
@ -82,7 +82,7 @@ pub enum MembershipEventFilter {
|
|||||||
_Custom(String),
|
_Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, feature = "server"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use ruma_api::IncomingRequest as _;
|
use ruma_api::IncomingRequest as _;
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
|
//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use ruma_api::{ruma_api, Metadata};
|
||||||
|
|
||||||
use ruma_api::{
|
|
||||||
error::{FromHttpRequestError, IntoHttpError},
|
|
||||||
ruma_api, try_deserialize, Metadata,
|
|
||||||
};
|
|
||||||
use ruma_events::{AnyMessageEventContent, EventContent as _};
|
use ruma_events::{AnyMessageEventContent, EventContent as _};
|
||||||
use ruma_identifiers::{EventId, RoomId};
|
use ruma_identifiers::{EventId, RoomId};
|
||||||
use ruma_serde::Outgoing;
|
use ruma_serde::Outgoing;
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -75,7 +69,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
self,
|
self,
|
||||||
base_url: &str,
|
base_url: &str,
|
||||||
access_token: Option<&str>,
|
access_token: Option<&str>,
|
||||||
) -> Result<http::Request<Vec<u8>>, IntoHttpError> {
|
) -> Result<http::Request<Vec<u8>>, ruma_api::error::IntoHttpError> {
|
||||||
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
@ -93,7 +87,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
AUTHORIZATION,
|
AUTHORIZATION,
|
||||||
HeaderValue::from_str(&format!(
|
HeaderValue::from_str(&format!(
|
||||||
"Bearer {}",
|
"Bearer {}",
|
||||||
access_token.ok_or(IntoHttpError::NeedsAuthentication)?
|
access_token.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?
|
||||||
))?,
|
))?,
|
||||||
)
|
)
|
||||||
.body(serde_json::to_vec(&self.content)?)?;
|
.body(serde_json::to_vec(&self.content)?)?;
|
||||||
@ -111,7 +105,12 @@ impl ruma_api::IncomingRequest for IncomingRequest {
|
|||||||
|
|
||||||
fn try_from_http_request(
|
fn try_from_http_request(
|
||||||
request: http::Request<Vec<u8>>,
|
request: http::Request<Vec<u8>>,
|
||||||
) -> Result<Self, FromHttpRequestError> {
|
) -> Result<Self, ruma_api::error::FromHttpRequestError> {
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use ruma_api::try_deserialize;
|
||||||
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
||||||
|
|
||||||
let room_id = {
|
let room_id = {
|
||||||
|
@ -49,7 +49,7 @@ impl Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, feature = "server"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use ruma_api::IncomingRequest as _;
|
use ruma_api::IncomingRequest as _;
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
|
//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
|
||||||
|
|
||||||
use std::{borrow::Cow, convert::TryFrom};
|
use ruma_api::{ruma_api, Metadata};
|
||||||
|
|
||||||
use ruma_api::{
|
|
||||||
error::{FromHttpRequestError, IntoHttpError},
|
|
||||||
ruma_api, try_deserialize, Metadata,
|
|
||||||
};
|
|
||||||
use ruma_events::EventType;
|
use ruma_events::EventType;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
use ruma_serde::Outgoing;
|
use ruma_serde::Outgoing;
|
||||||
@ -72,7 +67,9 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
self,
|
self,
|
||||||
base_url: &str,
|
base_url: &str,
|
||||||
access_token: Option<&str>,
|
access_token: Option<&str>,
|
||||||
) -> Result<http::Request<Vec<u8>>, IntoHttpError> {
|
) -> Result<http::Request<Vec<u8>>, ruma_api::error::IntoHttpError> {
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
@ -96,7 +93,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
AUTHORIZATION,
|
AUTHORIZATION,
|
||||||
HeaderValue::from_str(&format!(
|
HeaderValue::from_str(&format!(
|
||||||
"Bearer {}",
|
"Bearer {}",
|
||||||
access_token.ok_or(IntoHttpError::NeedsAuthentication)?
|
access_token.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?
|
||||||
))?,
|
))?,
|
||||||
)
|
)
|
||||||
.body(Vec::new())
|
.body(Vec::new())
|
||||||
@ -113,7 +110,11 @@ impl ruma_api::IncomingRequest for IncomingRequest {
|
|||||||
|
|
||||||
fn try_from_http_request(
|
fn try_from_http_request(
|
||||||
request: http::Request<Vec<u8>>,
|
request: http::Request<Vec<u8>>,
|
||||||
) -> Result<Self, FromHttpRequestError> {
|
) -> Result<Self, ruma_api::error::FromHttpRequestError> {
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use ruma_api::try_deserialize;
|
||||||
|
|
||||||
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
||||||
|
|
||||||
let room_id = {
|
let room_id = {
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
|
//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
|
||||||
|
|
||||||
use std::{borrow::Cow, convert::TryFrom};
|
use ruma_api::{ruma_api, Metadata};
|
||||||
|
|
||||||
use ruma_api::{
|
|
||||||
error::{FromHttpRequestError, IntoHttpError},
|
|
||||||
ruma_api, try_deserialize, Metadata,
|
|
||||||
};
|
|
||||||
use ruma_events::{AnyStateEventContent, EventContent as _};
|
use ruma_events::{AnyStateEventContent, EventContent as _};
|
||||||
use ruma_identifiers::{EventId, RoomId};
|
use ruma_identifiers::{EventId, RoomId};
|
||||||
use ruma_serde::Outgoing;
|
use ruma_serde::Outgoing;
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -71,7 +65,9 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
self,
|
self,
|
||||||
base_url: &str,
|
base_url: &str,
|
||||||
access_token: Option<&str>,
|
access_token: Option<&str>,
|
||||||
) -> Result<http::Request<Vec<u8>>, IntoHttpError> {
|
) -> Result<http::Request<Vec<u8>>, ruma_api::error::IntoHttpError> {
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
use http::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
@ -95,7 +91,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
AUTHORIZATION,
|
AUTHORIZATION,
|
||||||
HeaderValue::from_str(&format!(
|
HeaderValue::from_str(&format!(
|
||||||
"Bearer {}",
|
"Bearer {}",
|
||||||
access_token.ok_or(IntoHttpError::NeedsAuthentication)?
|
access_token.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?
|
||||||
))?,
|
))?,
|
||||||
)
|
)
|
||||||
.body(serde_json::to_vec(&self.content)?)?;
|
.body(serde_json::to_vec(&self.content)?)?;
|
||||||
@ -113,7 +109,12 @@ impl ruma_api::IncomingRequest for IncomingRequest {
|
|||||||
|
|
||||||
fn try_from_http_request(
|
fn try_from_http_request(
|
||||||
request: http::Request<Vec<u8>>,
|
request: http::Request<Vec<u8>>,
|
||||||
) -> Result<Self, FromHttpRequestError> {
|
) -> Result<Self, ruma_api::error::FromHttpRequestError> {
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use ruma_api::try_deserialize;
|
||||||
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
let path_segments: Vec<&str> = request.uri().path()[1..].split('/').collect();
|
||||||
|
|
||||||
let room_id = {
|
let room_id = {
|
||||||
|
@ -530,13 +530,42 @@ impl DeviceLists {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use matches::assert_matches;
|
|
||||||
use ruma_api::{IncomingRequest as _, OutgoingRequest as _};
|
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{Filter, IncomingFilter, IncomingRequest, PresenceState, Request, Timeline};
|
use super::Timeline;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn timeline_serde() {
|
||||||
|
let timeline = Timeline { limited: true, prev_batch: None, events: vec![] };
|
||||||
|
|
||||||
|
let timeline_serialized = json!({
|
||||||
|
"limited": true,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(to_json_value(timeline).unwrap(), timeline_serialized);
|
||||||
|
|
||||||
|
let timeline_deserialized: Timeline = from_json_value(timeline_serialized).unwrap();
|
||||||
|
assert_eq!(timeline_deserialized.limited, true);
|
||||||
|
|
||||||
|
let timeline_default = Timeline::default();
|
||||||
|
|
||||||
|
let timeline_default_serialized = json!({});
|
||||||
|
|
||||||
|
assert_eq!(to_json_value(timeline_default).unwrap(), timeline_default_serialized);
|
||||||
|
|
||||||
|
let timeline_default_deserialized: Timeline =
|
||||||
|
from_json_value(timeline_default_serialized).unwrap();
|
||||||
|
assert_eq!(timeline_default_deserialized.limited, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(test, feature = "client"))]
|
||||||
|
mod client_tests {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use ruma_api::OutgoingRequest as _;
|
||||||
|
|
||||||
|
use super::{Filter, PresenceState, Request};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_all_params() {
|
fn serialize_all_params() {
|
||||||
@ -560,6 +589,17 @@ mod tests {
|
|||||||
assert!(query.contains("set_presence=offline"));
|
assert!(query.contains("set_presence=offline"));
|
||||||
assert!(query.contains("timeout=30000"))
|
assert!(query.contains("timeout=30000"))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(test, feature = "server"))]
|
||||||
|
mod server_tests {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use matches::assert_matches;
|
||||||
|
use ruma_api::IncomingRequest as _;
|
||||||
|
use ruma_common::presence::PresenceState;
|
||||||
|
|
||||||
|
use super::{IncomingFilter, IncomingRequest};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_all_query_params() {
|
fn deserialize_all_query_params() {
|
||||||
@ -634,28 +674,4 @@ mod tests {
|
|||||||
assert_eq!(req.set_presence, PresenceState::Online);
|
assert_eq!(req.set_presence, PresenceState::Online);
|
||||||
assert_eq!(req.timeout, Some(Duration::from_millis(0)));
|
assert_eq!(req.timeout, Some(Duration::from_millis(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn timeline_serde() {
|
|
||||||
let timeline = Timeline { limited: true, prev_batch: None, events: vec![] };
|
|
||||||
|
|
||||||
let timeline_serialized = json!({
|
|
||||||
"limited": true,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_eq!(to_json_value(timeline).unwrap(), timeline_serialized);
|
|
||||||
|
|
||||||
let timeline_deserialized: Timeline = from_json_value(timeline_serialized).unwrap();
|
|
||||||
assert_eq!(timeline_deserialized.limited, true);
|
|
||||||
|
|
||||||
let timeline_default = Timeline::default();
|
|
||||||
|
|
||||||
let timeline_default_serialized = json!({});
|
|
||||||
|
|
||||||
assert_eq!(to_json_value(timeline_default).unwrap(), timeline_default_serialized);
|
|
||||||
|
|
||||||
let timeline_default_deserialized: Timeline =
|
|
||||||
from_json_value(timeline_default_serialized).unwrap();
|
|
||||||
assert_eq!(timeline_default_deserialized.limited, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ impl Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, feature = "server"))]
|
||||||
mod tests {
|
mod server_tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
|
@ -58,24 +58,59 @@ pub use ruma_signatures as signatures;
|
|||||||
pub mod api {
|
pub mod api {
|
||||||
pub use ruma_api::*;
|
pub use ruma_api::*;
|
||||||
|
|
||||||
#[cfg(feature = "appservice-api")]
|
#[cfg(feature = "ruma-appservice-api")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "appservice-api")))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "appservice-api",
|
||||||
|
feature = "appservice-api-c",
|
||||||
|
feature = "appservice-api-s"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ruma_appservice_api as appservice;
|
pub use ruma_appservice_api as appservice;
|
||||||
#[cfg(feature = "client-api")]
|
#[cfg(feature = "ruma-client-api")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "client-api")))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "client-api",
|
||||||
|
feature = "client-api-c",
|
||||||
|
feature = "client-api-s"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ruma_client_api as client;
|
pub use ruma_client_api as client;
|
||||||
#[cfg(feature = "federation-api")]
|
#[cfg(feature = "ruma-federation-api")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "federation-api")))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "federation-api",
|
||||||
|
feature = "federation-api-c",
|
||||||
|
feature = "federation-api-s"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ruma_federation_api as federation;
|
pub use ruma_federation_api as federation;
|
||||||
#[cfg(feature = "identity-service-api")]
|
#[cfg(feature = "ruma-identity-service-api")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "identity-service-api")))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "identity-service-api",
|
||||||
|
feature = "identity-service-api-c",
|
||||||
|
feature = "identity-service-api-s"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ruma_identity_service_api as identity_service;
|
pub use ruma_identity_service_api as identity_service;
|
||||||
#[cfg(feature = "push-gateway-api")]
|
#[cfg(feature = "ruma-push-gateway-api")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "push-gateway-api")))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "push-gateway-api",
|
||||||
|
feature = "push-gateway-api-c",
|
||||||
|
feature = "push-gateway-api-s"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ruma_push_gateway_api as push_gateway;
|
pub use ruma_push_gateway_api as push_gateway;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user