basic list test

This commit is contained in:
Robin Appelman 2020-11-29 20:27:02 +01:00
commit 6970dfe2a2
3 changed files with 82 additions and 18 deletions

26
Cargo.lock generated
View file

@ -336,7 +336,9 @@ dependencies = [
[[package]]
name = "demostf-client"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4806484ba6677ab29aa75bc15a89f16fa7715fc546274285ac014ecf189cf14b"
dependencies = [
"chrono",
"hex",
@ -1076,9 +1078,9 @@ dependencies = [
[[package]]
name = "num_enum"
version = "0.4.3"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca565a7df06f3d4b485494f25ba05da1435950f4dc263440eda7a6fa9b8e36e4"
checksum = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066"
dependencies = [
"derivative",
"num_enum_derive",
@ -1086,9 +1088,9 @@ dependencies = [
[[package]]
name = "num_enum_derive"
version = "0.4.3"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d"
checksum = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@ -1148,22 +1150,22 @@ dependencies = [
[[package]]
name = "parse-display"
version = "0.1.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd87725635cbae7fe960f91f55a114ed104e637790317cc8d9197ea16b058010"
checksum = "12035532e456d9f4f59fcfa3834dc5f45b391d9029f5287292bf41960b05ce91"
dependencies = [
"lazy_static",
"once_cell",
"parse-display-derive",
"regex",
]
[[package]]
name = "parse-display-derive"
version = "0.1.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc52b391380aa8550348736a356bf028f5469391d580533a566e97543f55e813"
checksum = "449f5881ab953fa168d60a57dd182a3e1fdeff16bb9bdd309145fbd8f32326ec"
dependencies = [
"lazy_static",
"once_cell",
"proc-macro2",
"quote",
"regex",
@ -1812,6 +1814,8 @@ checksum = "36474e732d1affd3a6ed582781b3683df3d0563714c59c39591e8ff707cf078e"
[[package]]
name = "tf-demo-parser"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aefd410a68248ad4192147294341137e0068467b3f2101ee0a6528b1c36123cf"
dependencies = [
"bitbuffer",
"enumflags2",

View file

@ -5,13 +5,13 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018"
[dependencies]
demostf-client = { version = "0.1.2", default-features = false, features = ["rustls-tls"], path = "../api-client" }
demostf-client = { version = "0.1.2", default-features = false, features = ["rustls-tls"] }
sqlx = { version = "0.4", features = ["postgres", "runtime-tokio-rustls"] }
dotenv = "0.15.0"
color-eyre = "0.5.8"
colored = "2"
tokio = { version = "0.2", features = ["macros", "rt-core"] }
tf-demo-parser = { version = "0.1", path = "../tf-demo-parser" }
tf-demo-parser = "0.1"
bitbuffer = "0.7.1"
[profile.dev.package.tf-demo-parser]

View file

@ -21,7 +21,10 @@ macro_rules! assert_object_eq {
#[tokio::main]
async fn main() -> Result<()> {
let harness = Harness::new(&dotenv::var("BASE_URL")?, &dotenv::var("DB_URL")?).await?;
let gully_data = include_bytes!("../data/granary.dem");
let granary_data = include_bytes!("../data/granary.dem");
let process_data = include_bytes!("../data/process.dem");
let warmfrost_data = include_bytes!("../data/warmfrost.dem");
let coalplant_data = include_bytes!("../data/coalplant.dem");
Test::run(
"Upload with invalid credentials",
@ -31,7 +34,7 @@ async fn main() -> Result<()> {
let result = client
.upload_demo(
String::from("test.dem"),
gully_data.to_vec(),
granary_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("wrong_token"),
@ -58,7 +61,7 @@ async fn main() -> Result<()> {
&harness,
|test| async move {
let parser =
DemoParser::new(BitReadBuffer::new(gully_data.to_vec(), LittleEndian).into());
DemoParser::new(BitReadBuffer::new(granary_data.to_vec(), LittleEndian).into());
let (header, state) = parser
.parse()
.map_err(|_| Report::msg("Failed to parse demo"))?;
@ -69,7 +72,7 @@ async fn main() -> Result<()> {
Ok(client
.upload_demo(
String::from("test.dem"),
gully_data.to_vec(),
granary_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
@ -130,7 +133,7 @@ async fn main() -> Result<()> {
let new_id = client
.upload_demo(
String::from("test.dem"),
gully_data.to_vec(),
granary_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
@ -147,6 +150,63 @@ async fn main() -> Result<()> {
)
.await;
Test::run("Listings", &harness, |test| async move {
test.step("upload", |client| async move {
client
.upload_demo(
String::from("test1.dem"),
granary_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
)
.await?;
client
.upload_demo(
String::from("test2.dem"),
process_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
)
.await?;
client
.upload_demo(
String::from("test3.dem"),
warmfrost_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
)
.await?;
client
.upload_demo(
String::from("test3.dem"),
coalplant_data.to_vec(),
String::from("RED"),
String::from("BLUE"),
String::from("token"),
)
.await?;
Ok(())
})
.await?;
test.step("list defaults", |client| async move {
let list = client.list(ListParams::default(), 1).await?;
assert_eq(list.len(), 4)?;
assert_eq(list[0].id, 4)?;
assert_eq(list[1].id, 3)?;
assert_eq(list[2].id, 2)?;
assert_eq(list[3].id, 1)?;
Ok(())
})
.await?;
Ok(())
})
.await;
Ok(())
}