From: Ian Jackson Date: Sun, 21 Feb 2021 23:09:00 +0000 (+0000) Subject: apitest: Break out core part of setup_static_users X-Git-Tag: otter-0.4.0~389 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8f16479babb89746632b4929efee539f27317761;p=otter.git apitest: Break out core part of setup_static_users NFC Signed-off-by: Ian Jackson --- diff --git a/apitest.rs b/apitest.rs index 55c980fc..0ecb47ab 100644 --- a/apitest.rs +++ b/apitest.rs @@ -718,7 +718,58 @@ pub fn prepare_game(ds: &DirSubst, table: &str) -> InstanceName { instance } -// ---------- core entrypoint, for wdriver too ---------- +// ==================== post-setup facilities ==================== + +// -------------------- static users -------------------- + +pub struct StaticUserSetup { + pub nick: &'static str, + pub url: String, +} + +impl DirSubst { + #[throws(AE)] + pub fn setup_static_users + Result> + (&mut self, layout: PresentationLayout, mut f: F) + -> Vec + { + #[throws(AE)] + fn mk(su: &DirSubst, layout: PresentationLayout, u: StaticUser) + -> StaticUserSetup + { + let nick: &str = u.into(); + let token = u.get_str("Token").expect("StaticUser missing Token"); + let pl = AbbrevPresentationLayout(layout).to_string(); + let subst = su.also([ + ("nick", nick), + ("token", token), + ("pl", &pl), + ].iter()); + + su.otter(&subst + .ss("--super \ + --account server:@nick@ \ + --fixed-token @token@ \ + join-game server::dummy")?)?; + let url = subst.subst("@url@/@pl@?@token@")?; + StaticUserSetup { nick, url } + } + + StaticUser::iter().map( + |u| (||{ + let ssu = mk(self, layout, u).context("create")?; + let w = f(ssu).context("set up")?; + Ok::<_,AE>(w) + })() + .with_context(|| format!("{:?}", u)) + .context("make static user") + ) + .collect::,AE>>()? + } +} + +// ==================== core entrypoint, for wdriver too ==================== #[throws(AE)] pub fn setup_core(module_paths: &[&str]) -> diff --git a/wdriver.rs b/wdriver.rs index 9773fb64..1fc055a0 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -695,33 +695,12 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) { impl Setup { #[throws(AE)] pub fn setup_static_users(&mut self, instance: &Instance) -> Vec { - #[throws(AE)] - fn mk(su: &mut Setup, instance: &Instance, u: StaticUser) -> Window { - let nick: &str = u.into(); - let token = u.get_str("Token").expect("StaticUser missing Token"); - let pl = AbbrevPresentationLayout(su.opts.layout).to_string(); - let subst = su.ds.also([ - ("nick", nick), - ("token", token), - ("pl", &pl), - ].iter()); - su.ds.otter(&subst - .ss("--super \ - --account server:@nick@ \ - --fixed-token @token@ \ - join-game server::dummy")?)?; - let w = su.new_window(instance, nick)?; - let url = subst.subst("@url@/@pl@?@token@")?; - su.w(&w)?.get(url)?; - su.w(&w)?.screenshot("initial", log::Level::Trace)?; - w - } - StaticUser::iter().map( - |u| mk(self, instance, u) - .with_context(|| format!("{:?}", u)) - .context("make static user") - ) - .collect::,AE>>()? + self.core.ds.clone().setup_static_users(self.opts.layout, |sus|{ + let w = self.new_window(instance, sus.nick)?; + self.w(&w)?.get(sus.url)?; + self.w(&w)?.screenshot("initial", log::Level::Trace)?; + Ok(w) + })? } }