SeaBattle/src/test/client.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

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;
}