From a6798c78c42afaf22b79c0a55c3d3b38b300fd89 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 4 Apr 2021 18:45:08 +0100 Subject: [PATCH] apitest: Provide PlayerId everywhere Signed-off-by: Ian Jackson --- apitest/apitest.rs | 16 ++++++++++++---- apitest/at-otter.rs | 4 +++- wdriver/wdriver.rs | 13 +++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 59e00a1b..2670962d 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -721,15 +721,18 @@ pub fn prepare_game(ds: &DirSubst, table: &str) -> InstanceName { pub struct StaticUserSetup { pub nick: &'static str, pub url: String, + pub player: PlayerId, } impl DirSubst { #[throws(AE)] - pub fn setup_static_users(&self, layout: PresentationLayout) + pub fn setup_static_users(&self, mgmt_conn: &mut MgmtChannelForGame, + layout: PresentationLayout) -> Vec { #[throws(AE)] - fn mk(su: &DirSubst, layout: PresentationLayout, u: StaticUser) + fn mk(su: &DirSubst, mgmt_conn: &mut MgmtChannelForGame, + layout: PresentationLayout, u: StaticUser) -> StaticUserSetup { let nick: &str = u.into(); @@ -746,13 +749,18 @@ impl DirSubst { --account server:@nick@ \ --fixed-token @token@ \ join-game @table@")?)?; + + let player = mgmt_conn.has_player( + &subst.subst("server:@nick@")?.parse()? + )?.unwrap().0; + let url = subst.subst("@url@/@pl@?@token@")?; - StaticUserSetup { nick, url } + StaticUserSetup { nick, url, player } } StaticUser::iter().map( |u| (||{ - let ssu = mk(self, layout, u).context("create")?; + let ssu = mk(self, mgmt_conn, layout, u).context("create")?; Ok::<_,AE>(ssu) })() .with_context(|| format!("{:?}", u)) diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index dddfa050..85483db4 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -646,10 +646,12 @@ fn main() { &mut |_|false )?; let spec = su.ds.game_spec_data()?; + let mut mc = su.mgmt_conn(); let [alice, bob]: [Player; 2] = - su.ds.setup_static_users(default())? + su.ds.setup_static_users(&mut mc, default())? .into_iter().map(|sus| Player { nick: sus.nick, url: sus.url }) .collect::>().into_inner().unwrap(); + drop(mc); let su_rc = Rc::new(RefCell::new(su)); tests(Ctx { opts, spec, su_rc, alice, bob })?; diff --git a/wdriver/wdriver.rs b/wdriver/wdriver.rs index 8a8b8e50..34c09cf8 100644 --- a/wdriver/wdriver.rs +++ b/wdriver/wdriver.rs @@ -55,6 +55,7 @@ deref_to_field_mut!{Setup, SetupCore, core} #[derive(Debug)] pub struct Window { pub name: String, + pub player: PlayerId, pub instance: InstanceName, } @@ -383,7 +384,8 @@ fn check_window_name_sanity(name: &str) -> &str { impl Setup { #[throws(AE)] - pub fn new_window<'s>(&'s mut self, instance: &Instance, name: &str) + pub fn new_window<'s>(&'s mut self, instance: &Instance, name: &str, + player: PlayerId) -> Window { let name = check_window_name_sanity(name)?; let window = (||{ @@ -411,6 +413,7 @@ impl Setup { Ok::<_,AE>(Window { name: name.to_owned(), instance: instance.0.clone(), + player, }) })() .with_context(|| name.to_owned()) @@ -631,6 +634,7 @@ impl Drop for Setup { let w = Window { name: name.clone(), instance: TABLE.parse().context(TABLE)?, + player: default(), }; self.w(&w)?.screenshot("final", log::Level::Info) .context(name) @@ -674,11 +678,12 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) { impl Setup { #[throws(AE)] pub fn setup_static_users(&mut self, instance: &Instance) -> Vec { - self.core.ds.clone() - .setup_static_users(self.opts.layout)? + let susus = self.core.ds.clone() + .setup_static_users(&mut self.mgmt_conn(), self.opts.layout)?; + susus .into_iter().map(|sus| { - let w = self.new_window(instance, sus.nick)?; + let w = self.new_window(instance, sus.nick, sus.player)?; self.w(&w)?.get(sus.url)?; self.w(&w)?.screenshot("initial", log::Level::Trace)?; Ok::<_,AE>(w) -- 2.30.2