chiark / gitweb /
apitest: Break out core part of setup_static_users
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Feb 2021 23:09:00 +0000 (23:09 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Feb 2021 23:09:00 +0000 (23:09 +0000)
NFC

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest.rs
wdriver.rs

index 55c980fc0ab06451647c1007c9e0a0a59713a78b..0ecb47ab9f08d6b65bde50acb87c41e21a78e5d5 100644 (file)
@@ -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
+    <W, F: FnMut(StaticUserSetup) -> Result<W, AE>>
+    (&mut self, layout: PresentationLayout, mut f: F)
+     -> Vec<W>
+  {
+    #[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::<Result<Vec<W>,AE>>()?
+  }
+}
+
+// ==================== core entrypoint, for wdriver too ====================
 
 #[throws(AE)]
 pub fn setup_core<O>(module_paths: &[&str]) ->
index 9773fb644bb6c98d8a15198a09020adfb2f98eef..1fc055a0360ec31a1df8ceec1af8a26277df1ad9 100644 (file)
@@ -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<Window> {
-    #[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::<Result<Vec<Window>,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)
+    })?
   }
 }