From: Ian Jackson Date: Sun, 12 Jun 2022 19:29:08 +0000 (+0100) Subject: apitest: Provide initial_[vp]id_by_desc_glob X-Git-Tag: otter-1.2.0~42 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e2da401cf86cc452320fddfc4daf9c3caf43c9e7;p=otter.git apitest: Provide initial_[vp]id_by_desc_glob The plan is to replace literal pieceids with this. Signed-off-by: Ian Jackson --- diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 8bad2194..d7932bee 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -89,6 +89,7 @@ pub struct SetupCore { pub server_child: Child, pub wanted_tests: TrackWantedTests, pub cln: cleanup_notify::Handle, + pub initial_pieces_cache: Option>, } #[derive(Clone,Debug)] @@ -1053,6 +1054,30 @@ impl MgmtChannel { } } +impl SetupCore { + #[throws(AE)] + pub fn initial_id_by_desc_glob(&mut self, desc_glob: &str) -> PieceId { + let pieces = self.initial_pieces_cache.get_or_insert_with(||{ + self.mgmt_conn.borrow_mut().list_pieces().unwrap().0 + }); + + let glob = glob::Pattern::new(desc_glob).unwrap(); + pieces.iter().filter_map(|mgpi| { + + let vis = mgpi.visible.as_ref()?; + glob.matches(vis.desc_html.as_html_str()).then(||())?; + Some(mgpi.piece) + + }).exactly_one().map_err(|_| anyhow!("not exactly one {:?}", desc_glob))? + } + + #[throws(AE)] + pub fn initial_vpid_by_desc_glob(&mut self, desc_glob: &str) -> String { + let id = self.initial_id_by_desc_glob(desc_glob)?; + VisiblePieceId::from(id.data()).to_string() + } +} + // ==================== core entrypoint, for wdriver too ==================== #[throws(AE)] @@ -1125,6 +1150,7 @@ pub fn setup_core(module_paths: &[&str]) -> mgmt_conn: mgmt_conn.into(), server_child, wanted_tests, + initial_pieces_cache: None, }) } diff --git a/src/imports.rs b/src/imports.rs index 10baa440..2db507e0 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -83,6 +83,7 @@ pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError}; pub use crate::commands::{MgmtCommand, MgmtResponse}; pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse}; pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode}; +pub use crate::commands::{MgmtGamePieceInfo}; pub use crate::commands::{ProgressUpdateMode}; pub use crate::debugreader::DebugReader; pub use crate::error::*;