91 lines
2.1 KiB
Rust
91 lines
2.1 KiB
Rust
use crate::environment::Environment;
|
|
use crate::shell_interface::{
|
|
CommandOutput, CommandResult, ExitStatus, ShellCommand, ShellInterface, StartError,
|
|
};
|
|
use std::collections::{HashMap, VecDeque};
|
|
use std::ffi::{OsStr, OsString};
|
|
use std::io::Error;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug)]
|
|
pub struct TestEnvironment {
|
|
/// passed command line arguments
|
|
args_os: Vec<OsString>,
|
|
/// set environment variables - we assume a pure environment by default
|
|
env_vars: HashMap<OsString, OsString>,
|
|
/// home directory, relative to the target/test folder
|
|
home_dir: PathBuf,
|
|
/// pending lines of std input
|
|
stdin: VecDeque<String>,
|
|
/// whether an ssh agent has been started successfully
|
|
ssh_agent_started: bool,
|
|
// TODO ssh servers and local server
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct SshServer {
|
|
pub name: String,
|
|
pub home_dir: FsEntry,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct FsEntry {
|
|
pub name: OsString,
|
|
pub kind: FsEntryKind,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum FsEntryKind {
|
|
Directory(Dir),
|
|
File {
|
|
contents: String,
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Dir {
|
|
pub contents: Vec<FsEntry>,
|
|
}
|
|
|
|
impl Environment for TestEnvironment {
|
|
fn args_os(&self) -> Vec<OsString> {
|
|
self.args_os.clone()
|
|
}
|
|
|
|
fn var_os<K>(&self, key: K) -> Option<OsString>
|
|
where
|
|
K: AsRef<OsStr>
|
|
{
|
|
self.env_vars.get(key.as_ref()).map(|s| s.into())
|
|
}
|
|
|
|
fn set_var<K, V>(&mut self, key: K, value: V)
|
|
where
|
|
K: AsRef<OsStr>,
|
|
V: AsRef<OsStr>,
|
|
{
|
|
self.env_vars.insert(key.as_ref().into(), value.as_ref().into());
|
|
}
|
|
|
|
fn get_home_directory(&self) -> Option<PathBuf> {
|
|
PathBuf::from("target/integration_test").join(&self.home_dir).into()
|
|
}
|
|
|
|
fn read_line(&mut self) -> Result<String, Error> {
|
|
self.stdin.pop_front().ok_or_else(|| Error::other("Unexpected call to read_line: No input prepared"))
|
|
}
|
|
}
|
|
|
|
impl ShellInterface for TestEnvironment {
|
|
fn run_command(&mut self, command: ShellCommand) -> CommandResult<ExitStatus, StartError> {
|
|
todo!()
|
|
}
|
|
|
|
fn collect_command_output(
|
|
&mut self,
|
|
command: ShellCommand,
|
|
) -> CommandResult<CommandOutput, StartError> {
|
|
todo!()
|
|
}
|
|
}
|