mirror of
https://codeberg.org/demostf/api-test.git
synced 2026-06-03 09:34:10 +02:00
add basic private demo tests
This commit is contained in:
parent
a265dc4f3f
commit
24dddb5e6d
9 changed files with 509 additions and 281 deletions
1
.env
1
.env
|
|
@ -1,3 +1,4 @@
|
|||
DB_URL=postgres://postgres:test@localhost:15432/postgres
|
||||
BASE_URL=http://localhost:8888
|
||||
EDIT_KEY=edit
|
||||
ACCESS_KEY=access
|
||||
666
Cargo.lock
generated
666
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,7 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
demostf-client = { version = "0.4.5" }
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@ Start the test with the following environment variables
|
|||
- `DB_URL` - [sqlx](https://github.com/launchbadge/sqlx) database url for the database used by the api
|
||||
- `BASE_URL` - base url for the api
|
||||
- `EDIT_KEY` - edit key for the api
|
||||
- `ACCESS_KEY` - access key for the api
|
||||
|
||||
Note that the test suite is destructive, all data saved in the database will be wiped for each test run.
|
||||
|
|
|
|||
30
flake.lock
generated
30
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1733688869,
|
||||
"narHash": "sha256-KrhxxFj1CjESDrL5+u/zsVH0K+Ik9tvoac/oFPoxSB8=",
|
||||
"lastModified": 1742394900,
|
||||
"narHash": "sha256-vVOAp9ahvnU+fQoKd4SEXB2JG2wbENkpqcwlkIXgUC0=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "604637106e420ad99907cae401e13ab6b452e7d9",
|
||||
"rev": "70947c1908108c0c551ddfd73d4f750ff2ea67cd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -22,11 +22,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1734957624,
|
||||
"narHash": "sha256-RbvX9lf9lWQwG9vTXkscOiWTrKf8lzjyeOvW/v8IuBY=",
|
||||
"lastModified": 1745844883,
|
||||
"narHash": "sha256-4t9eR291RIgYo29MvRQ04QgmjZNad3e5sBr40tLhLTM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "flakelight",
|
||||
"rev": "8c226ea0166784b02d4a58fbb015f9c01250221e",
|
||||
"rev": "78ad7409722c554effa360208417244c54ef398f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -44,11 +44,11 @@
|
|||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735052218,
|
||||
"narHash": "sha256-I30wh6G8fSUO4EseexxiDXcxyUhXR6C8BvEeKn6xyfE=",
|
||||
"lastModified": 1745623947,
|
||||
"narHash": "sha256-7Jt9a6YjBeRPso1VaRsH6ZnqNzt+MlcmVM7MNBSLVEI=",
|
||||
"owner": "icewind1991",
|
||||
"repo": "mill-scale",
|
||||
"rev": "7e45bb598ff63a8416ee3c26743b20644563bd93",
|
||||
"rev": "45597aa1134a3ea397c4441e36ac1d836a5de000",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -59,11 +59,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1734875076,
|
||||
"narHash": "sha256-Pzyb+YNG5u3zP79zoi8HXYMs15Q5dfjDgwCdUI5B0nY=",
|
||||
"lastModified": 1746183838,
|
||||
"narHash": "sha256-kwaaguGkAqTZ1oK0yXeQ3ayYjs8u/W7eEfrFpFfIDFA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "1807c2b91223227ad5599d7067a61665c52d1295",
|
||||
"rev": "bf3287dac860542719fe7554e21e686108716879",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -88,11 +88,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1733884434,
|
||||
"narHash": "sha256-8GXR9kC07dyOIshAyfZhG11xfvBRSZzYghnZ2weOKJU=",
|
||||
"lastModified": 1742697269,
|
||||
"narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "d0483df44ddf0fd1985f564abccbe568e020ddf2",
|
||||
"rev": "01973c84732f9275c50c5f075dd1f54cc04b3316",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ in
|
|||
src = fetchFromGitHub {
|
||||
owner = "demostf";
|
||||
repo = "api";
|
||||
rev = "1a8380360b993226ae1c6fcc226011e03a6c1467";
|
||||
hash = "sha256-JcBRU1N44tt0QDLnj6z9MCT3V2s2dkf+JbpWb1rmXnY=";
|
||||
rev = "52b9bc09fd187bf3bbc11dbe4443af0e07a716a4";
|
||||
hash = "sha256-iMU7C2g76w5d5CtxRW5H50FxY+UlOc5gSpjxxbVyqUw=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-EYWCR2aJAoyWvEX+SML4Fb3F3KGcUtwCgqhAGT6ZjZ4=";
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@
|
|||
DB_USERNAME = "demostf";
|
||||
APP_ROOT = "http://localhost";
|
||||
EDIT_SECRET = "edit";
|
||||
ACCESS_KEY = "access";
|
||||
PARSER_PATH = "${pkgs.demostf-parser}/bin/parse_demo";
|
||||
};
|
||||
user = "demostf";
|
||||
|
|
@ -108,7 +109,7 @@
|
|||
testBinary = lib.getExe pkgs.demostf-api-test;
|
||||
initSql = pkgs.fetchurl {
|
||||
url = "https://github.com/demostf/db/raw/refs/heads/master/schema.sql";
|
||||
hash = "sha256-AwXN9mh9CRk6HWdvyUR+YdBkpmExNIDOIeDMz6XqjEQ=";
|
||||
hash = "sha256-tdMYDxlvpuQRxHglX46sCldxzsh1cDxkch2lGWnFH8E=";
|
||||
};
|
||||
in ''
|
||||
machine.succeed("mkdir /demos && chmod 0777 /demos");
|
||||
|
|
@ -120,6 +121,7 @@
|
|||
machine.wait_until_succeeds("curl http://127.0.0.1", timeout=45)
|
||||
machine.succeed("DB_URL='postgres://demostf:test@localhost/demostf'\
|
||||
BASE_URL='http://localhost/'\
|
||||
ACCESS_KEY='access'\
|
||||
EDIT_KEY='edit'\
|
||||
${testBinary}", timeout=180)
|
||||
'';
|
||||
|
|
|
|||
80
src/main.rs
80
src/main.rs
|
|
@ -29,6 +29,8 @@ async fn main() -> Result<()> {
|
|||
|
||||
let edit_key = dotenv::var("EDIT_KEY")?;
|
||||
let edit_key = &edit_key;
|
||||
let access_key = dotenv::var("ACCESS_KEY")?;
|
||||
let access_key = &access_key;
|
||||
|
||||
let mut success = true;
|
||||
|
||||
|
|
@ -578,6 +580,84 @@ async fn main() -> Result<()> {
|
|||
})
|
||||
.await;
|
||||
|
||||
success &= Test::run("Private demos", &harness, |test| async move {
|
||||
let id = test
|
||||
.step("upload", |client| async move {
|
||||
Ok(client
|
||||
.upload_private_demo(
|
||||
String::from("test.dem"),
|
||||
granary_data.to_vec(),
|
||||
String::from("RED"),
|
||||
String::from("BLUE"),
|
||||
String::from("token"),
|
||||
)
|
||||
.await?)
|
||||
})
|
||||
.await?;
|
||||
|
||||
assert_eq(id, 1)?;
|
||||
|
||||
test.step("get without key", |client| async move {
|
||||
let demo = client.get(id).await?;
|
||||
assert_object_eq!(demo => {
|
||||
id == 1,
|
||||
name == "test.dem",
|
||||
map == "cp_granary_pro_rc8",
|
||||
red_score == 0,
|
||||
blue_score == 1,
|
||||
player_count == 12,
|
||||
url == "",
|
||||
backend == "",
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
test.step("get with key", |client| async move {
|
||||
let mut client = client.clone();
|
||||
client.set_access_key(access_key.clone());
|
||||
|
||||
let demo = client.get(id).await?;
|
||||
assert_object_eq!(demo => {
|
||||
id == 1,
|
||||
name == "test.dem",
|
||||
map == "cp_granary_pro_rc8",
|
||||
red_score == 0,
|
||||
blue_score == 1,
|
||||
player_count == 12,
|
||||
url == "https://localhost/ec/68/ec681d1b4846a7e3cb2c129fcbd858ac_test.dem",
|
||||
backend == "static",
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
test.step("get with wrong key", |client| async move {
|
||||
let mut client = client.clone();
|
||||
client.set_access_key("wrong".into());
|
||||
|
||||
let demo = client.get(id).await?;
|
||||
assert_object_eq!(demo => {
|
||||
id == 1,
|
||||
name == "test.dem",
|
||||
map == "cp_granary_pro_rc8",
|
||||
red_score == 0,
|
||||
blue_score == 1,
|
||||
player_count == 12,
|
||||
url == "",
|
||||
backend == "",
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await;
|
||||
|
||||
if !success {
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ docker run -d --name api-test-db -e POSTGRES_PASSWORD=test -p 15432:5432 demostf
|
|||
docker run -d --name api-test-fpm --link api-test-db:db -v /tmp/api-test-data:/demos \
|
||||
-e DEMO_ROOT=/demos -e DEMO_HOST=localhost -e DB_TYPE=pgsql \
|
||||
-e DB_HOST=db -e DB_PORT=5432 -e DB_DATABASE=postgres -e DB_USERNAME=postgres \
|
||||
-e DB_PASSWORD=test -e APP_ROOT=http://api.localhost -e EDIT_SECRET=edit \
|
||||
-e DB_PASSWORD=test -e APP_ROOT=http://api.localhost -e EDIT_SECRET=edit -e ACCESS_KEY=access \
|
||||
demostf/api
|
||||
docker run -d --name api-test --link api-test-fpm:api -p 8888:80 demostf/api-nginx-test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue