with engine

This commit is contained in:
2023-01-27 21:57:39 +01:00
parent 1e88bb3270
commit ee655d02ef
8 changed files with 217 additions and 3 deletions

46
src/engine.rs Normal file
View File

@@ -0,0 +1,46 @@
use crate::{
cli_session::CliSession, config::Config, connect_params::ConnectParams, downloader::Downloader,
};
pub struct Engine {}
impl Engine {
pub fn new() -> Self {
Self {}
}
fn from_cli(&self, cfg: &Config) -> eyre::Result<ConnectParams> {
let cli = Downloader::new("0.3.10".into())?.get_cli()?;
let cli_session = CliSession::new();
Ok(cli_session.connect(cfg, &cli)?)
}
pub fn start(&self, cfg: &Config) -> eyre::Result<ConnectParams> {
// TODO: Add from existing session as well
self.from_cli(cfg)
}
}
#[cfg(test)]
mod tests {
use crate::{config::Config, connect_params::ConnectParams};
use super::Engine;
// TODO: these tests potentially have a race condition
#[test]
fn engine_can_start() {
let engine = Engine::new();
let params = engine.start(&Config::new(None, None, None, None)).unwrap();
assert_ne!(
params,
ConnectParams {
port: 123,
session_token: "123".into()
}
)
}
}