tests: Split into submodules
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
7a687df552
commit
db7237069c
3 changed files with 85 additions and 35 deletions
65
src/tests/iq.rs
Normal file
65
src/tests/iq.rs
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
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<BareJid, Room> = HashMap::new();
|
||||
|
||||
component.expect(reply);
|
||||
handle_stanza(&mut component, &mut rooms).await.unwrap();
|
||||
component.assert();
|
||||
}
|
20
src/tests/mod.rs
Normal file
20
src/tests/mod.rs
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
#[cfg(test)]
|
||||
mod iq;
|
||||
|
||||
#[cfg(test)]
|
||||
mod presence;
|
|
@ -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<BareJid, Room> = 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();
|
Loading…
Reference in a new issue