2022-09-14 15:36:16 +00:00
|
|
|
use crate::args::Args;
|
|
|
|
use crate::bot_client;
|
|
|
|
use crate::data::GameRules;
|
|
|
|
use crate::server::start_server;
|
|
|
|
use crate::test::network_utils::wait_for_port;
|
|
|
|
use crate::test::TestPort;
|
|
|
|
use tokio::task;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn invalid_port() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
|
|
|
|
bot_client::run_client(
|
|
|
|
&TestPort::ClientInvalidPort.as_url(),
|
|
|
|
&GameRules::random_players_rules(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap_err();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn invalid_rules() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
|
|
|
|
let local_set = task::LocalSet::new();
|
|
|
|
local_set
|
|
|
|
.run_until(async move {
|
|
|
|
let mut rules = GameRules::random_players_rules();
|
|
|
|
rules.map_width = 0;
|
|
|
|
|
|
|
|
task::spawn_local(start_server(Args::for_test(TestPort::ClientInvalidRules)));
|
|
|
|
wait_for_port(TestPort::ClientInvalidRules.port()).await;
|
|
|
|
|
|
|
|
bot_client::run_client(&TestPort::ClientInvalidRules.as_url(), &rules)
|
|
|
|
.await
|
|
|
|
.unwrap_err();
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
2022-09-14 16:02:11 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn full_game() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
|
|
|
|
let local_set = task::LocalSet::new();
|
|
|
|
local_set
|
|
|
|
.run_until(async move {
|
|
|
|
let rules = GameRules::random_players_rules();
|
|
|
|
task::spawn_local(start_server(Args::for_test(TestPort::ClientInvalidRules)));
|
|
|
|
wait_for_port(TestPort::ClientInvalidRules.port()).await;
|
|
|
|
|
|
|
|
bot_client::run_client(&TestPort::ClientInvalidRules.as_url(), &rules)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|