bakare/src/main.rs

66 lines
1.7 KiB
Rust
Raw Normal View History

2018-09-02 11:13:37 +01:00
extern crate crypto;
2018-09-01 09:44:13 +01:00
extern crate tempfile;
2018-09-02 11:13:37 +01:00
extern crate dir_diff;
use std::path::Path;
struct BackupEngine;
impl BackupEngine {
2018-09-02 14:18:58 +01:00
fn new(source_path: &Path, repository_path: &Path) -> Self {
2018-09-02 11:13:37 +01:00
BackupEngine {}
}
fn backup(&self) {}
}
struct RestoreEngine;
impl RestoreEngine {
2018-09-02 14:18:58 +01:00
fn new(repository_path: &Path, target_path: &Path) -> Self {
2018-09-02 11:13:37 +01:00
RestoreEngine {}
}
fn restore(&self) {}
}
2018-08-17 17:58:18 +01:00
2018-09-01 09:44:13 +01:00
mod rustback {
2018-08-17 17:58:18 +01:00
2018-08-18 18:39:40 +01:00
use super::*;
#[cfg(test)]
mod should {
2018-09-01 09:44:13 +01:00
use super::*;
use std::fs::File;
use std::io::Error;
2018-09-02 11:13:37 +01:00
use std::io::{self, Write};
use tempfile::tempdir;
use tempfile::tempfile_in;
use tempfile::TempDir;
use dir_diff::is_different;
2018-09-02 13:27:04 +01:00
use std::fs::write;
2018-09-01 09:44:13 +01:00
2018-08-18 18:39:40 +01:00
#[test]
2018-09-01 09:44:13 +01:00
fn be_able_to_restore_backed_up_files() -> Result<(), Error> {
2018-09-02 11:13:37 +01:00
let source = tempdir()?;
2018-09-02 13:27:04 +01:00
File::create(source.path().join("first"))?.write_all("some contents".as_bytes())?;
File::create(source.path().join("second"))?.write_all("some contents".as_bytes())?;
File::create(source.path().join("third"))?.write_all("some other contents".as_bytes())?;
2018-09-01 09:44:13 +01:00
2018-09-02 14:18:58 +01:00
let repository = tempdir()?;
let backup_engine = BackupEngine::new(&source.path(), &repository.path());
2018-09-02 11:13:37 +01:00
backup_engine.backup();
2018-09-01 09:44:13 +01:00
2018-09-02 14:18:58 +01:00
let restore_target = tempdir()?;
let restore_engine = RestoreEngine::new(&repository.path(), &restore_target.path());
2018-09-02 11:13:37 +01:00
restore_engine.restore();
2018-09-01 09:44:13 +01:00
2018-09-02 14:18:58 +01:00
let is_source_and_destination_different = is_different(&source.path(), &restore_target.path()).unwrap();
2018-09-02 11:13:37 +01:00
assert!(!is_source_and_destination_different);
2018-09-01 09:44:13 +01:00
Ok(())
}
}
2018-08-18 18:39:40 +01:00
2018-09-01 09:44:13 +01:00
}
2018-08-18 18:39:40 +01:00