From db7237069c541f8ff3daf419092f7e6a8f0aba91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 19 Sep 2022 23:18:04 +0200 Subject: [PATCH] tests: Split into submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/tests/iq.rs | 65 +++++++++++++++++++++++++++++ src/tests/mod.rs | 20 +++++++++ src/{tests.rs => tests/presence.rs} | 35 ---------------- 3 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 src/tests/iq.rs create mode 100644 src/tests/mod.rs rename src/{tests.rs => tests/presence.rs} (95%) diff --git a/src/tests/iq.rs b/src/tests/iq.rs new file mode 100644 index 0000000..97f0324 --- /dev/null +++ b/src/tests/iq.rs @@ -0,0 +1,65 @@ +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at your +// option) any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License +// for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::component::TestComponent; +use crate::handlers::handle_stanza; +use crate::room::Room; + +use std::collections::HashMap; +use std::str::FromStr; + +use lazy_static::lazy_static; +use xmpp_parsers::{ + iq::{Iq, IqType}, + stanza_error::{DefinedCondition, ErrorType, StanzaError}, + BareJid, Element, FullJid, Jid, +}; + +lazy_static! { + static ref COMPONENT_JID: BareJid = BareJid::from_str("muc.component").unwrap(); +} + +#[tokio::test] +async fn test_iq_unimplemented() { + let from = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap()); + let to = Jid::Bare(COMPONENT_JID.clone()); + + let disco: Element = Iq { + from: Some(from.clone()), + to: Some(to.clone()), + id: String::from("disco"), + payload: IqType::Get(Element::builder("x", "urn:example:unimplemented").build()), + } + .into(); + + let reply: Element = Iq::from_error( + "disco", + StanzaError::new( + ErrorType::Cancel, + DefinedCondition::ServiceUnavailable, + "en", + "No handler defined for this kind of iq.", + ), + ) + .with_from(to) + .with_to(from) + .into(); + + let mut component = TestComponent::new(vec![disco]); + let mut rooms: HashMap = HashMap::new(); + + component.expect(reply); + handle_stanza(&mut component, &mut rooms).await.unwrap(); + component.assert(); +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs new file mode 100644 index 0000000..ceb3cec --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1,20 @@ +// Copyright (C) 2022-2099 The crate authors. +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at your +// option) any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License +// for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#[cfg(test)] +mod iq; + +#[cfg(test)] +mod presence; diff --git a/src/tests.rs b/src/tests/presence.rs similarity index 95% rename from src/tests.rs rename to src/tests/presence.rs index 83151ce..65eff7e 100644 --- a/src/tests.rs +++ b/src/tests/presence.rs @@ -23,7 +23,6 @@ use std::str::FromStr; use lazy_static::lazy_static; use xmpp_parsers::{ delay::Delay, - iq::{Iq, IqType}, message::{Message, MessageType, Subject as MessageSubject}, muc::{ user::{Affiliation, Item as MucItem, Role, Status as MucStatus}, @@ -38,40 +37,6 @@ lazy_static! { static ref COMPONENT_JID: BareJid = BareJid::from_str("muc.component").unwrap(); } -#[tokio::test] -async fn test_iq_unimplemented() { - let from = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap()); - let to = Jid::Bare(COMPONENT_JID.clone()); - - let disco: Element = Iq { - from: Some(from.clone()), - to: Some(to.clone()), - id: String::from("disco"), - payload: IqType::Get(Element::builder("x", "urn:example:unimplemented").build()), - } - .into(); - - let reply: Element = Iq::from_error( - "disco", - StanzaError::new( - ErrorType::Cancel, - DefinedCondition::ServiceUnavailable, - "en", - "No handler defined for this kind of iq.", - ), - ) - .with_from(to) - .with_to(from) - .into(); - - let mut component = TestComponent::new(vec![disco]); - let mut rooms: HashMap = HashMap::new(); - - component.expect(reply); - handle_stanza(&mut component, &mut rooms).await.unwrap(); - component.assert(); -} - #[tokio::test] async fn test_join_presence_empty_room() { let from = FullJid::from_str("foo@bar/qxx").unwrap();