mirror of
https://codeberg.org/demostf/api-test.git
synced 2026-11-30 04:00:49 +01:00
cargo updates
This commit is contained in:
parent
9ca5bda3a0
commit
2811824f0f
4 changed files with 1183 additions and 1277 deletions
2510
Cargo.lock
generated
2510
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
18
Cargo.toml
18
Cargo.toml
|
|
@ -1,19 +1,19 @@
|
||||||
[package]
|
[package]
|
||||||
name = "api-test"
|
name = "api-test"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
demostf-client = { version = "0.4.6" }
|
|
||||||
sqlx = { version = "0.6.0", features = ["postgres", "runtime-tokio-rustls"] }
|
|
||||||
dotenv = "0.15.0"
|
|
||||||
color-eyre = "0.6.1"
|
color-eyre = "0.6.1"
|
||||||
colored = "2.0.0"
|
colored = "3.1.1"
|
||||||
tokio = { version = "1.19.2", features = ["macros"] }
|
demostf-client = { version = "0.5.1" }
|
||||||
tf-demo-parser = "0.5.1"
|
dotenv = "0.15.0"
|
||||||
|
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio"] }
|
||||||
|
tf-demo-parser = "0.7.1"
|
||||||
|
tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
[profile.dev.package.bitbuffer]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[profile.dev.package.tf-demo-parser]
|
[profile.dev.package.tf-demo-parser]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
[profile.dev.package.bitbuffer]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use demostf_client::ApiClient;
|
use demostf_client::ApiClient;
|
||||||
use sqlx::postgres::PgPoolOptions;
|
use sqlx::postgres::PgPoolOptions;
|
||||||
use sqlx::{Pool, Postgres};
|
use sqlx::{AssertSqlSafe, Pool, Postgres};
|
||||||
|
|
||||||
pub struct Harness {
|
pub struct Harness {
|
||||||
client: ApiClient,
|
client: ApiClient,
|
||||||
|
|
@ -34,17 +34,20 @@ impl Harness {
|
||||||
let mut transaction = self.db.begin().await?;
|
let mut transaction = self.db.begin().await?;
|
||||||
|
|
||||||
for table in &tables {
|
for table in &tables {
|
||||||
sqlx::query(&format!("TRUNCATE TABLE {}", table))
|
sqlx::query(AssertSqlSafe(format!("TRUNCATE TABLE {}", table)))
|
||||||
.execute(&mut transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
|
||||||
sqlx::query(&format!("ALTER SEQUENCE {}_id_seq RESTART with 1", table))
|
|
||||||
.execute(&mut transaction)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
sqlx::query(AssertSqlSafe(format!(
|
||||||
|
"ALTER SEQUENCE {}_id_seq RESTART with 1",
|
||||||
|
table
|
||||||
|
)))
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlx::query("INSERT INTO users(steamid, name, avatar, token)\
|
sqlx::query("INSERT INTO users(steamid, name, avatar, token)\
|
||||||
VALUES(76561198024494988, 'Icewind', 'http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/75/75b84075b70535c5cfb3499af03b3e4e7a7b556f_medium.jpg', 'token')")
|
VALUES(76561198024494988, 'Icewind', 'http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/75/75b84075b70535c5cfb3499af03b3e4e7a7b556f_medium.jpg', 'token')")
|
||||||
.execute(&mut transaction).await?;
|
.execute(&mut *transaction).await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -5,7 +5,7 @@ use crate::harness::Harness;
|
||||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||||
use demostf_client::{ChatMessage, Class, Demo, GameType, ListOrder, 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::convert::TryFrom;
|
use std::{convert::TryFrom, str::FromStr};
|
||||||
use tf_demo_parser::{demo::header::Header, DemoParser, MatchState};
|
use tf_demo_parser::{demo::header::Header, DemoParser, MatchState};
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
|
|
||||||
|
|
@ -315,7 +315,10 @@ async fn main() -> Result<()> {
|
||||||
let players = list[0].get_players(client).await?;
|
let players = list[0].get_players(client).await?;
|
||||||
let reconnected_player = players
|
let reconnected_player = players
|
||||||
.iter()
|
.iter()
|
||||||
.find(|player| player.user.steam_id == SteamID::from(76561197998883586))
|
.find(|player| {
|
||||||
|
player.user.steam_id
|
||||||
|
== SteamID::try_from(76561197998883586).expect("valid steamid")
|
||||||
|
})
|
||||||
.expect("player not found");
|
.expect("player not found");
|
||||||
|
|
||||||
// note that these include post-game kills so the exact values might need to change if the parser ever starts excluding those
|
// note that these include post-game kills so the exact values might need to change if the parser ever starts excluding those
|
||||||
|
|
@ -415,7 +418,7 @@ async fn main() -> Result<()> {
|
||||||
test.step("list by uploader", |client| async move {
|
test.step("list by uploader", |client| async move {
|
||||||
let list = client
|
let list = client
|
||||||
.list_uploads(
|
.list_uploads(
|
||||||
SteamID::from(76561197992327511),
|
SteamID::try_from(76561197992327511).expect("valid steamid"),
|
||||||
ListParams::default().with_order(ListOrder::Ascending),
|
ListParams::default().with_order(ListOrder::Ascending),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
@ -424,7 +427,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let list = client
|
let list = client
|
||||||
.list_uploads(
|
.list_uploads(
|
||||||
SteamID::from(76561198024494988),
|
SteamID::try_from(76561198024494988).expect("valid steamid"),
|
||||||
ListParams::default().with_order(ListOrder::Ascending),
|
ListParams::default().with_order(ListOrder::Ascending),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
@ -719,10 +722,10 @@ fn verify_demo(api_result: &Demo, header: &Header, state: &MatchState) -> Result
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
players.sort_by(|a, b| {
|
players.sort_by(|a, b| {
|
||||||
SteamID::try_from(a.steam_id.as_str())
|
SteamID::from_str(a.steam_id.as_str())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account_id()
|
.account_id()
|
||||||
.cmp(&SteamID::try_from(b.steam_id.as_str()).unwrap().account_id())
|
.cmp(&SteamID::from_str(b.steam_id.as_str()).unwrap().account_id())
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut api_players = api_result.players.clone().unwrap();
|
let mut api_players = api_result.players.clone().unwrap();
|
||||||
|
|
@ -743,7 +746,7 @@ fn verify_demo(api_result: &Demo, header: &Header, state: &MatchState) -> Result
|
||||||
})?;
|
})?;
|
||||||
assert_eq(
|
assert_eq(
|
||||||
&api_player.user.steam_id,
|
&api_player.user.steam_id,
|
||||||
&SteamID::try_from(player.steam_id.as_str()).unwrap(),
|
&SteamID::from_str(player.steam_id.as_str()).unwrap(),
|
||||||
)
|
)
|
||||||
.wrap_err_with(|| format!("Failed to compare steam id for {}", api_player.user.name))?;
|
.wrap_err_with(|| format!("Failed to compare steam id for {}", api_player.user.name))?;
|
||||||
assert_eq(map_team(api_player.team), player.team)
|
assert_eq(map_team(api_player.team), player.team)
|
||||||
|
|
@ -784,7 +787,7 @@ fn verify_chat(chat: &[ChatMessage], state: &MatchState) -> Result<()> {
|
||||||
.wrap_err("Failed to compare number of chat messages")?;
|
.wrap_err("Failed to compare number of chat messages")?;
|
||||||
|
|
||||||
let mut demo_chat = state.chat.clone();
|
let mut demo_chat = state.chat.clone();
|
||||||
demo_chat.sort_by(|a, b| a.tick.cmp(&b.tick));
|
demo_chat.sort_by_key(|a| a.tick);
|
||||||
|
|
||||||
for (api_chat, chat) in chat.iter().zip(demo_chat.iter()) {
|
for (api_chat, chat) in chat.iter().zip(demo_chat.iter()) {
|
||||||
assert_eq(&api_chat.message, &chat.text).wrap_err("Failed to compare chat message")?;
|
assert_eq(&api_chat.message, &chat.text).wrap_err("Failed to compare chat message")?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue