aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-09-20 21:11:19 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-09-20 21:11:19 +0200
commit9643ccf6d69cc34f56fff454f1c0aa3e34a93d08 (patch)
treeffc947ac1bcea84cfb6ec4048ac8316c7fc6907b
parent9e05a9bdd5f7e5ddc8a2170c031a47d669432832 (diff)
downloadplanetwars.dev-9643ccf6d69cc34f56fff454f1c0aa3e34a93d08.tar.xz
planetwars.dev-9643ccf6d69cc34f56fff454f1c0aa3e34a93d08.zip
add a basic matchrunner test
-rw-r--r--planetwars-matchrunner/Cargo.toml3
-rw-r--r--planetwars-matchrunner/maps/abc.json25
-rw-r--r--planetwars-matchrunner/tests/test_matchrunner.rs41
3 files changed, 69 insertions, 0 deletions
diff --git a/planetwars-matchrunner/Cargo.toml b/planetwars-matchrunner/Cargo.toml
index e0b6af0..10d1c99 100644
--- a/planetwars-matchrunner/Cargo.toml
+++ b/planetwars-matchrunner/Cargo.toml
@@ -18,3 +18,6 @@ chrono = { version = "0.4", features = ["serde"] }
bollard = { git = "https://github.com/fussybeaver/bollard", rev = "c5d87a4934c70a04f9c649fedb241dbd4943c927" }
bytes = "1.1"
async-trait = "0.1"
+
+[dev-dependencies]
+tempfile = "3" \ No newline at end of file
diff --git a/planetwars-matchrunner/maps/abc.json b/planetwars-matchrunner/maps/abc.json
new file mode 100644
index 0000000..70462e7
--- /dev/null
+++ b/planetwars-matchrunner/maps/abc.json
@@ -0,0 +1,25 @@
+{
+ "planets": [
+ {
+ "name": "a",
+ "x": -3,
+ "y": 0,
+ "owner": 1,
+ "ship_count": 5
+ },
+ {
+ "name": "b",
+ "x": 0,
+ "y": 0,
+ "ship_count": 5
+ },
+ {
+ "name": "c",
+ "x": 3,
+ "y": 0,
+ "owner": 2,
+ "ship_count": 5
+ }
+ ]
+}
+
diff --git a/planetwars-matchrunner/tests/test_matchrunner.rs b/planetwars-matchrunner/tests/test_matchrunner.rs
new file mode 100644
index 0000000..0da1836
--- /dev/null
+++ b/planetwars-matchrunner/tests/test_matchrunner.rs
@@ -0,0 +1,41 @@
+use std::io::BufRead;
+use std::path::PathBuf;
+
+use planetwars_matchrunner::{docker_runner::DockerBotSpec, run_match, MatchConfig, MatchPlayer};
+
+const PYTHON_IMAGE: &str = "python:3.10-slim-buster";
+
+#[tokio::test]
+async fn match_does_run() {
+ let simplebot_path = std::fs::canonicalize("bots/simplebot").unwrap();
+ let simplebot_path_str = simplebot_path.as_os_str().to_str().unwrap();
+
+ let log_file = tempfile::NamedTempFile::new().unwrap();
+
+ let bot = DockerBotSpec {
+ image: PYTHON_IMAGE.to_string(),
+ binds: Some(vec![format!("{}:{}", simplebot_path_str, "/workdir")]),
+ argv: Some(vec!["python".to_string(), "simplebot.py".to_string()]),
+ working_dir: Some("/workdir".to_string()),
+ pull: false,
+ credentials: None,
+ };
+ let config = MatchConfig {
+ map_name: "hex".to_string(),
+ map_path: PathBuf::from("maps/abc.json"),
+ log_path: PathBuf::from(log_file.path()),
+ players: vec![
+ MatchPlayer {
+ bot_spec: Box::new(bot.clone()),
+ },
+ MatchPlayer {
+ bot_spec: Box::new(bot.clone()),
+ },
+ ],
+ };
+
+ run_match(config).await;
+
+ let line_count = std::io::BufReader::new(log_file.as_file()).lines().count();
+ assert!(line_count > 0);
+}