aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner/tests/test_matchrunner.rs
blob: 0da18365dae7f2a564232a3d5f9151bac76b2715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}