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
|
||||
with:
|
||||
command: fmt
|
||||
args: "--check -p mgmt-api -p lavina"
|
||||
args: "--check -p mgmt-api -p lavina-core -p projection-irc"
|
||||
- name: cargo check
|
||||
uses: https://github.com/actions-rs/cargo@v1
|
||||
with:
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use std::time::Duration;
|
||||
|
||||
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::{player::PlayerRegistry, room::RoomRegistry};
|
||||
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> {
|
||||
reader: BufReader<ReadHalf<'a>>,
|
||||
|
@ -20,11 +21,13 @@ impl<'a> TestScope<'a> {
|
|||
fn new(stream: &mut TcpStream) -> TestScope<'_> {
|
||||
let (reader, writer) = stream.split();
|
||||
let reader = BufReader::new(reader);
|
||||
let buffer = vec![];
|
||||
let timeout = Duration::from_millis(100);
|
||||
TestScope {
|
||||
reader,
|
||||
writer,
|
||||
buffer: vec![],
|
||||
timeout: Duration::from_millis(100),
|
||||
buffer,
|
||||
timeout,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,13 +44,6 @@ impl<'a> TestScope<'a> {
|
|||
self.buffer.clear();
|
||||
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]
|
||||
|
@ -73,10 +69,10 @@ async fn scenario_basic() -> Result<()> {
|
|||
let mut stream = TcpStream::connect(server.addr).await?;
|
||||
let mut s = TestScope::new(&mut stream);
|
||||
|
||||
s.expect(":testserver NOTICE * :Welcome to my server!").await?;
|
||||
s.send("PASS password").await?;
|
||||
s.send("NICK tester").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 002 tester :Welcome to Kek Server").await?;
|
||||
s.expect(":testserver 003 tester :Welcome to Kek Server").await?;
|
||||
|
|
Loading…
Reference in New Issue