2020-01-14 09:52:27 +01:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
pub(crate) struct TestEnv {
|
|
|
|
env: Env,
|
|
|
|
err: Capture,
|
|
|
|
out: Capture,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestEnv {
|
2020-02-04 19:54:41 +01:00
|
|
|
pub(crate) fn new(env: Env, err: Capture, out: Capture) -> TestEnv {
|
2020-01-14 09:52:27 +01:00
|
|
|
Self { err, env, out }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn err(&self) -> String {
|
|
|
|
self.err.string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn out(&self) -> String {
|
|
|
|
self.out.string()
|
|
|
|
}
|
2020-02-05 06:29:53 +01:00
|
|
|
|
|
|
|
pub(crate) fn out_bytes(&self) -> Vec<u8> {
|
|
|
|
self.out.bytes()
|
|
|
|
}
|
2020-02-06 03:32:09 +01:00
|
|
|
|
|
|
|
pub(crate) fn create_dir(&self, path: impl AsRef<Path>) {
|
|
|
|
fs::create_dir_all(self.env.resolve(path.as_ref())).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn create_file(&self, path: impl AsRef<Path>, bytes: impl AsRef<[u8]>) {
|
|
|
|
fs::write(self.env.resolve(path), bytes.as_ref()).unwrap();
|
|
|
|
}
|
2020-02-14 09:12:49 +01:00
|
|
|
|
|
|
|
pub(crate) fn load_torrent(&self, filename: impl AsRef<Path>) -> Metainfo {
|
|
|
|
Metainfo::load(self.env.resolve(filename.as_ref())).unwrap()
|
|
|
|
}
|
2020-01-14 09:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for TestEnv {
|
|
|
|
type Target = Env;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.env
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for TestEnv {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.env
|
|
|
|
}
|
|
|
|
}
|