forked from lavina/lavina
fix
This commit is contained in:
parent
d866a5f37a
commit
d28c2b2f2f
|
@ -12,7 +12,7 @@ jobs:
|
||||||
uses: https://github.com/actions-rs/cargo@v1
|
uses: https://github.com/actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
args: "--check -p mgmt-api -p lavina"
|
args: "--check -p mgmt-api -p lavina-core -p projection-irc"
|
||||||
- name: cargo check
|
- name: cargo check
|
||||||
uses: https://github.com/actions-rs/cargo@v1
|
uses: https://github.com/actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use prometheus::Registry as MetricsRegistry;
|
||||||
|
use tokio::io::{AsyncWriteExt, BufReader};
|
||||||
|
use tokio::net::tcp::{ReadHalf, WriteHalf};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
use lavina_core::repo::{Storage, StorageConfig};
|
use lavina_core::repo::{Storage, StorageConfig};
|
||||||
use lavina_core::{player::PlayerRegistry, room::RoomRegistry};
|
use lavina_core::{player::PlayerRegistry, room::RoomRegistry};
|
||||||
use projection_irc::{launch, read_irc_message, ServerConfig};
|
use projection_irc::{launch, read_irc_message, ServerConfig};
|
||||||
use prometheus::Registry as MetricsRegistry;
|
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
|
||||||
use tokio::net::tcp::{ReadHalf, WriteHalf};
|
|
||||||
use tokio::net::TcpStream;
|
|
||||||
|
|
||||||
struct TestScope<'a> {
|
struct TestScope<'a> {
|
||||||
reader: BufReader<ReadHalf<'a>>,
|
reader: BufReader<ReadHalf<'a>>,
|
||||||
|
@ -20,11 +21,13 @@ impl<'a> TestScope<'a> {
|
||||||
fn new(stream: &mut TcpStream) -> TestScope<'_> {
|
fn new(stream: &mut TcpStream) -> TestScope<'_> {
|
||||||
let (reader, writer) = stream.split();
|
let (reader, writer) = stream.split();
|
||||||
let reader = BufReader::new(reader);
|
let reader = BufReader::new(reader);
|
||||||
|
let buffer = vec![];
|
||||||
|
let timeout = Duration::from_millis(100);
|
||||||
TestScope {
|
TestScope {
|
||||||
reader,
|
reader,
|
||||||
writer,
|
writer,
|
||||||
buffer: vec![],
|
buffer,
|
||||||
timeout: Duration::from_millis(100),
|
timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,13 +44,6 @@ impl<'a> TestScope<'a> {
|
||||||
self.buffer.clear();
|
self.buffer.clear();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn assert(&mut self, f: impl FnOnce(&str) -> Result<()>) -> Result<()> {
|
|
||||||
let len = tokio::time::timeout(self.timeout, read_irc_message(&mut self.reader, &mut self.buffer)).await??;
|
|
||||||
let res = f(std::str::from_utf8(&self.buffer[..len - 2])?);
|
|
||||||
self.buffer.clear();
|
|
||||||
res
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -73,10 +69,10 @@ async fn scenario_basic() -> Result<()> {
|
||||||
let mut stream = TcpStream::connect(server.addr).await?;
|
let mut stream = TcpStream::connect(server.addr).await?;
|
||||||
let mut s = TestScope::new(&mut stream);
|
let mut s = TestScope::new(&mut stream);
|
||||||
|
|
||||||
s.expect(":testserver NOTICE * :Welcome to my server!").await?;
|
|
||||||
s.send("PASS password").await?;
|
s.send("PASS password").await?;
|
||||||
s.send("NICK tester").await?;
|
s.send("NICK tester").await?;
|
||||||
s.send("USER UserName 0 * :Real Name").await?;
|
s.send("USER UserName 0 * :Real Name").await?;
|
||||||
|
s.expect(":testserver NOTICE * :Welcome to my server!").await?;
|
||||||
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
|
s.expect(":testserver 001 tester :Welcome to Kek Server").await?;
|
||||||
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
|
s.expect(":testserver 002 tester :Welcome to Kek Server").await?;
|
||||||
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
|
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
|
||||||
|
|
Loading…
Reference in New Issue