exp: cross

This commit is contained in:
2025-12-17 17:27:27 +01:00
parent 88313b0c51
commit 8e9e19a6ca
8 changed files with 330 additions and 54 deletions

View File

@@ -2,14 +2,15 @@ mod api;
mod local;
mod manager;
mod ssh;
mod schroot;
pub use api::{Context, ContextCommand};
pub use api::{Context, ContextCommand, ContextConfig};
pub use manager::ContextManager;
pub fn current_context() -> Context {
match ContextManager::new() {
Ok(mgr) => mgr.current(),
Err(_) => Context::Local,
Err(_) => Context::new(ContextConfig::Local),
}
}
@@ -25,7 +26,7 @@ mod tests {
let src_file = temp_dir.path().join("src.txt");
fs::write(&src_file, "local").unwrap();
let ctx = Context::Local;
let ctx = Context::new(ContextConfig::Local);
let dest = ctx.ensure_available(&src_file, "/tmp").unwrap();
// Should return canonical path
@@ -40,15 +41,14 @@ mod tests {
let mut mgr = ContextManager::with_path(path.clone());
// Add
let ssh_ctx = Context::Ssh {
let ssh_cfg = ContextConfig::Ssh {
host: "10.0.0.1".into(),
user: Some("admin".into()),
port: Some(2222),
};
mgr.add_context("myserver", ssh_ctx.clone()).unwrap();
mgr.add_context("myserver", ssh_cfg.clone()).unwrap();
assert!(mgr.get_context("myserver").is_some());
assert_eq!(mgr.get_context("myserver").unwrap(), &ssh_ctx);
// List
let list = mgr.list_contexts();
@@ -56,13 +56,11 @@ mod tests {
// Set Current
mgr.set_current("myserver").unwrap();
assert_eq!(mgr.current(), ssh_ctx);
assert_eq!(mgr.current_name(), Some("myserver".to_string()));
// Remove
mgr.remove_context("myserver").unwrap();
assert!(mgr.get_context("myserver").is_none());
assert_eq!(mgr.current(), Context::Local);
}
#[test]
@@ -72,7 +70,7 @@ mod tests {
{
let mut mgr = ContextManager::with_path(config_path.clone());
mgr.add_context("persistent", Context::Local).unwrap();
mgr.add_context("persistent", ContextConfig::Local).unwrap();
mgr.set_current("persistent").unwrap();
}