dagger-rs/crates/dagger-core/src/engine.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2023-01-28 13:33:30 +01:00
use std::process::Child;
2023-01-27 21:57:39 +01:00
use crate::{
cli_session::CliSession, config::Config, connect_params::ConnectParams, downloader::Downloader,
};
pub struct Engine {}
impl Engine {
pub fn new() -> Self {
Self {}
}
2023-01-28 13:33:30 +01:00
fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
2023-01-27 21:57:39 +01:00
let cli = Downloader::new("0.3.10".into())?.get_cli()?;
let cli_session = CliSession::new();
Ok(cli_session.connect(cfg, &cli)?)
}
2023-01-28 13:33:30 +01:00
pub fn start(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
2023-01-27 21:57:39 +01:00
// 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!(
2023-01-28 13:33:30 +01:00
params.0,
2023-01-27 21:57:39 +01:00
ConnectParams {
port: 123,
session_token: "123".into()
}
)
}
}