more filter tests

This commit is contained in:
Robin Appelman 2020-11-29 21:55:39 +01:00
commit a6b08da9a5
4 changed files with 132 additions and 10 deletions

4
Cargo.lock generated
View file

@ -336,9 +336,9 @@ dependencies = [
[[package]] [[package]]
name = "demostf-client" name = "demostf-client"
version = "0.1.3" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4806484ba6677ab29aa75bc15a89f16fa7715fc546274285ac014ecf189cf14b" checksum = "a93173a049ea144a947ebbaf115bce8a95f57396b9f5ffa7449d1b2e9da46607"
dependencies = [ dependencies = [
"chrono", "chrono",
"hex", "hex",

View file

@ -5,7 +5,7 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
demostf-client = { version = "0.1.2", default-features = false, features = ["rustls-tls"] } demostf-client = { version = "0.1.4", default-features = false, features = ["rustls-tls"] }
sqlx = { version = "0.4", features = ["postgres", "runtime-tokio-rustls"] } sqlx = { version = "0.4", features = ["postgres", "runtime-tokio-rustls"] }
dotenv = "0.15.0" dotenv = "0.15.0"
color-eyre = "0.5.8" color-eyre = "0.5.8"

BIN
data/ultiduo.dem Normal file

Binary file not shown.

View file

@ -4,10 +4,11 @@ mod report;
use crate::harness::Harness; use crate::harness::Harness;
use bitbuffer::{BitReadBuffer, LittleEndian}; use bitbuffer::{BitReadBuffer, LittleEndian};
use color_eyre::{eyre::WrapErr, Report, Result}; use color_eyre::{eyre::WrapErr, Report, Result};
use demostf_client::{ChatMessage, Class, Demo, ListParams, SteamID, Team}; use demostf_client::{ChatMessage, Class, Demo, GameType, ListOrder, ListParams, SteamID, Team};
use report::{assert_eq, Test}; use report::{assert_eq, Test};
use std::str::FromStr; use std::str::FromStr;
use tf_demo_parser::{demo::header::Header, DemoParser, MatchState}; use tf_demo_parser::{demo::header::Header, DemoParser, MatchState};
use tokio::time::Duration;
macro_rules! assert_object_eq { macro_rules! assert_object_eq {
($obj:expr => { $($name:ident == $value:expr),* }) => { ($obj:expr => { $($name:ident == $value:expr),* }) => {
@ -25,6 +26,7 @@ async fn main() -> Result<()> {
let process_data = include_bytes!("../data/process.dem"); let process_data = include_bytes!("../data/process.dem");
let warmfrost_data = include_bytes!("../data/warmfrost.dem"); let warmfrost_data = include_bytes!("../data/warmfrost.dem");
let coalplant_data = include_bytes!("../data/coalplant.dem"); let coalplant_data = include_bytes!("../data/coalplant.dem");
let ultiduo_data = include_bytes!("../data/ultiduo.dem");
Test::run( Test::run(
"Upload with invalid credentials", "Upload with invalid credentials",
@ -170,6 +172,10 @@ async fn main() -> Result<()> {
String::from("token"), String::from("token"),
) )
.await?; .await?;
// ensure there is some time separation
std::thread::sleep(Duration::from_secs(1));
client client
.upload_demo( .upload_demo(
String::from("test3.dem"), String::from("test3.dem"),
@ -179,26 +185,142 @@ async fn main() -> Result<()> {
String::from("token"), String::from("token"),
) )
.await?; .await?;
// ensure there is some time separation
std::thread::sleep(Duration::from_secs(1));
client client
.upload_demo( .upload_demo(
String::from("test3.dem"), String::from("test4.dem"),
coalplant_data.to_vec(), coalplant_data.to_vec(),
String::from("RED"), String::from("RED"),
String::from("BLUE"), String::from("BLUE"),
String::from("token"), String::from("token"),
) )
.await?; .await?;
client
.upload_demo(
String::from("test5.dem"),
ultiduo_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
)
.await?;
Ok(()) Ok(())
}) })
.await?; .await?;
test.step("list defaults", |client| async move { test.step("list defaults", |client| async move {
let list = client.list(ListParams::default(), 1).await?; let list = client.list(ListParams::default(), 1).await?;
assert_eq(list.len(), 4)?; assert_eq(list.len(), 5)?;
assert_eq(list[0].id, 5)?;
assert_eq(list[1].id, 4)?;
assert_eq(list[2].id, 3)?;
assert_eq(list[3].id, 2)?;
assert_eq(list[4].id, 1)?;
Ok(())
})
.await?;
test.step("list asc", |client| async move {
let list = client
.list(ListParams::default().with_order(ListOrder::Ascending), 1)
.await?;
assert_eq(list.len(), 5)?;
assert_eq(list[0].id, 1)?;
assert_eq(list[1].id, 2)?;
assert_eq(list[2].id, 3)?;
assert_eq(list[3].id, 4)?;
assert_eq(list[4].id, 5)?;
Ok(())
})
.await?;
test.step("list map filter", |client| async move {
let list = client
.list(ListParams::default().with_map("cp_process"), 1)
.await?;
assert_eq(list.len(), 1)?;
assert_eq(list[0].id, 2)?;
Ok(())
})
.await?;
test.step("list single player filter", |client| async move {
let list = client
.list(
ListParams::default().with_players(vec![76561197992327511]),
1,
)
.await?;
assert_eq(list.len(), 2)?;
assert_eq(list[0].id, 5)?;
assert_eq(list[1].id, 1)?;
Ok(())
})
.await?;
test.step("list multiple player filter", |client| async move {
let list = client
.list(
ListParams::default().with_players(vec![76561197992327511, 76561198024494988]),
1,
)
.await?;
assert_eq(list.len(), 1)?;
assert_eq(list[0].id, 1)?;
Ok(())
})
.await?;
test.step("list player and map filter", |client| async move {
let list = client
.list(
ListParams::default()
.with_players(vec![76561197992327511])
.with_map("cp_granary_pro"),
1,
)
.await?;
assert_eq(list.len(), 1)?;
assert_eq(list[0].id, 1)?;
Ok(())
})
.await?;
let first_time = test
.step("list type filter", |client| async move {
let list = client
.list(ListParams::default().with_type(GameType::Fours), 1)
.await?;
assert_eq(list.len(), 2)?;
assert_eq(list[0].id, 4)?; assert_eq(list[0].id, 4)?;
assert_eq(list[1].id, 3)?; assert_eq(list[1].id, 3)?;
assert_eq(list[2].id, 2)?; Ok(list[1].time)
assert_eq(list[3].id, 1)?; })
.await?;
test.step("list time filter after", |client| async move {
let list = client
.list(ListParams::default().with_after(first_time.clone()), 1)
.await?;
assert_eq(list.len(), 2)?;
assert_eq(list[0].id, 5)?;
assert_eq(list[1].id, 4)?;
Ok(())
})
.await?;
test.step("list time filter before", |client| async move {
let list = client
.list(ListParams::default().with_before(first_time.clone()), 1)
.await?;
assert_eq(list.len(), 2)?;
assert_eq(list[0].id, 2)?;
assert_eq(list[1].id, 1)?;
Ok(()) Ok(())
}) })
.await?; .await?;