Skip to content

Commit 47f353d

Browse files
committed
add unit tests
1 parent d623061 commit 47f353d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

crates/core/src/commands/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323

2424
/// This struct enhances `[SnapshotFile]` with the attribute `relevant`
2525
/// which indicates if the snapshot is relevant for copying.
26-
#[derive(Debug)]
26+
#[derive(Debug, PartialEq, Eq)]
2727
pub struct CopySnapshot {
2828
/// The snapshot
2929
pub sn: SnapshotFile,

crates/core/tests/integration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod integration {
2727
mod backup;
2828
mod check;
2929
mod chunker;
30+
mod copy;
3031
mod find;
3132
mod key;
3233
mod ls;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std::{path::PathBuf, str::FromStr};
2+
3+
use anyhow::Result;
4+
use pretty_assertions::assert_eq;
5+
use rstest::rstest;
6+
7+
use rustic_core::{BackupOptions, CheckOptions, CopySnapshot, repofile::SnapshotFile};
8+
9+
use super::{RepoOpen, TestSource, set_up_repo, tar_gz_testdata};
10+
11+
#[rstest]
12+
fn test_copy(tar_gz_testdata: Result<TestSource>, set_up_repo: Result<RepoOpen>) -> Result<()> {
13+
// uncomment for logging output
14+
// SimpleLogger::init(log::LevelFilter::Debug, Config::default())?;
15+
16+
// Fixtures
17+
let (source, repo) = (tar_gz_testdata?, set_up_repo?.to_indexed_ids()?);
18+
19+
let paths = &source.path_list();
20+
21+
// we use as_path to not depend on the actual tempdir
22+
let opts = BackupOptions::default().as_path(PathBuf::from_str("test")?);
23+
24+
// first backup
25+
let snap = repo.backup(&opts, paths, SnapshotFile::default())?;
26+
27+
// re-read index
28+
let repo = repo.to_indexed()?;
29+
30+
let target = super::set_up_repo()?;
31+
let relevant_snaps = target.relevant_copy_snapshots(|_| true, std::slice::from_ref(&snap))?;
32+
assert_eq!(
33+
relevant_snaps,
34+
vec![CopySnapshot {
35+
sn: snap.clone(),
36+
relevant: true
37+
}]
38+
);
39+
40+
let target = target.to_indexed_ids()?;
41+
repo.copy(&target, Some(&snap))?;
42+
let check_opts = CheckOptions::default();
43+
target.check(check_opts)?.is_ok()?;
44+
45+
Ok(())
46+
}

0 commit comments

Comments
 (0)