chiark / gitweb /
apitest: Provide PlayerId everywhere
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:45:08 +0000 (18:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:51:27 +0000 (18:51 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs
wdriver/wdriver.rs

index 59e00a1bbedb756cb716bdb591cf0accfdb9eee4..2670962d811fd89d864e2d44c01508c07b3926f9 100644 (file)
@@ -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<StaticUserSetup>
   {
     #[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))
index dddfa05056aaec186bfce6cd6ea75b0f3123cee7..85483db40225405671dd59bf3e4bdab33b846029 100644 (file)
@@ -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::<ArrayVec<_>>().into_inner().unwrap();
+    drop(mc);
     
     let su_rc = Rc::new(RefCell::new(su));
     tests(Ctx { opts, spec, su_rc, alice, bob })?;
index 8a8b8e50f6ce9b2a3c70e9e4bfc160666e800c67..34c09cf85cd03ed38fbea8e91379e9cf189bad02 100644 (file)
@@ -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<Window> {
-    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)