Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add backup integration tests using snapshots #175

Merged
merged 52 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c7552a7
tests: Add integration tests
aawsome Mar 5, 2024
f2ce7dc
temporary: Add logging output
aawsome Mar 9, 2024
e5f883f
use as_path
aawsome Mar 9, 2024
6cc4309
impl from_iter
simonsan Mar 12, 2024
e38d7e3
use PathList::from_iter
aawsome Mar 12, 2024
72add89
impl FromIterator for PathList
simonsan Mar 12, 2024
e5033cb
refactor test
simonsan Mar 12, 2024
db56e15
push base snapshots ci updates
simonsan Mar 12, 2024
5cde105
update snapshots
simonsan Mar 12, 2024
7fbd7d4
update snapshots
simonsan Mar 12, 2024
416cfd1
fix tempdir
simonsan Mar 12, 2024
b93ef46
update snapshots
simonsan Mar 12, 2024
88593bc
Merge branch 'main' into integration-tests
simonsan Mar 12, 2024
0bdc082
fix clippy
simonsan Mar 12, 2024
612d561
new snapshots
simonsan Mar 12, 2024
4e2bddd
update snapshots
simonsan Mar 12, 2024
5d34ac8
update
simonsan Mar 12, 2024
90efaab
fix clippy
simonsan Mar 12, 2024
674ba06
init snapshots
simonsan Mar 12, 2024
34d9e89
update vars
simonsan Mar 12, 2024
9c4223d
update snapshots
simonsan Mar 12, 2024
e31c9af
update snapshots II
simonsan Mar 12, 2024
1d359cf
cleanup, add new snapshots
simonsan Mar 12, 2024
8b60402
Add todo about TreeID newtype
simonsan Mar 12, 2024
a5dd67a
Merge branch 'main' into integration-tests
simonsan Mar 13, 2024
ece7322
add new snapshots
simonsan Mar 13, 2024
f5c4dfd
Merge branch 'main' into integration-tests
simonsan Mar 13, 2024
6bc24c3
use insta redactions to hide changing data
simonsan Mar 13, 2024
95bf5f6
Merge branch 'main' into integration-tests
simonsan Mar 13, 2024
e29c449
Merge branch 'main' into integration-tests
simonsan Mar 13, 2024
9c799c6
update snapshots
simonsan Mar 13, 2024
e00c13a
update snapshots
simonsan Mar 13, 2024
80e059b
update redactions and snapshots
simonsan Mar 13, 2024
cbe7379
update ubuntu snapshots
simonsan Mar 13, 2024
2141cda
add comment about testing
simonsan Mar 13, 2024
80c03a1
update redactions for trees
simonsan Mar 13, 2024
3f51f3b
get fancy with redactions
simonsan Mar 13, 2024
99f5e49
add command about binding to scope
simonsan Mar 13, 2024
4789b7e
fix clippy
simonsan Mar 13, 2024
e5ae77c
update snapshots
simonsan Mar 13, 2024
6d6c00a
update snapshots
simonsan Mar 13, 2024
996228d
ci: don't fail fast for tests
simonsan Mar 13, 2024
405c931
ci: don't run in release mode
simonsan Mar 13, 2024
ac82866
update snapshots and redactions
simonsan Mar 13, 2024
7c20621
update snapshots
simonsan Mar 13, 2024
b1e79af
Merge branch 'main' into integration-tests
simonsan Mar 13, 2024
971e24e
move out in-memory backend to rustic_testing
simonsan Mar 13, 2024
5bc8ad2
chore: manifest
simonsan Mar 13, 2024
199765b
code cleanups
aawsome Mar 13, 2024
b56d673
don`t redact content id
aawsome Mar 13, 2024
b0401b8
update windows snapshots
aawsome Mar 13, 2024
37caad3
fix clippy
aawsome Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update redactions and snapshots
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
simonsan committed Mar 13, 2024
commit 80e059bcdc74b62d84118e40dd2c6cd78fb147ba
240 changes: 94 additions & 146 deletions crates/core/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use flate2::read::GzDecoder;
use insta::assert_ron_snapshot;
use insta::{assert_ron_snapshot, Settings};
use pretty_assertions::assert_eq;
use rstest::fixture;
use rstest::rstest;
@@ -49,6 +49,45 @@ impl TestSource {
}
}

// Readme: https://docs.rs/insta/latest/insta/struct.Settings.html
#[fixture]
fn insta_summary_redaction() -> Settings {
let mut settings = insta::Settings::clone_current();

settings.add_redaction(".tree", "[tree_id]");
settings.add_redaction(".program_version", "[version]");
settings.add_redaction(".time", "[time]");
settings.add_redaction(".tags", "[tags]");
settings.add_redaction(".id", "[id]");
settings.add_redaction(".summary.backup_start", "[backup_start]");
settings.add_redaction(".summary.backup_end", "[backup_end]");
settings.add_redaction(".summary.backup_duration", "[backup_duration]");
settings.add_redaction(".summary.total_duration", "[total_duration]");
settings.add_redaction(".summary.data_added", "[data_added]");
settings.add_redaction(".summary.data_added_packed", "[data_added_packed]");
settings.add_redaction(
".summary.total_dirsize_processed",
"[total_dirsize_processed]",
);
settings.add_redaction(
".summary.data_added_trees_packed",
"[data_added_trees_packed]",
);
settings.add_redaction(".summary.data_added_trees", "[data_added_trees]");

settings
}

#[fixture]
fn insta_tree_redaction() -> Settings {
let mut settings = insta::Settings::clone_current();

settings.add_redaction(".nodes[].ctime", "[ctime]");
settings.add_redaction(".nodes[].content", "[content_id]");

settings
}

#[fixture]
fn tar_gz_testdata() -> Result<TestSource> {
let dir = tempdir()?;
@@ -77,6 +116,8 @@ struct TestSummary<'a>(&'a SnapshotFile);
fn test_backup_with_tar_gz_passes(
tar_gz_testdata: Result<TestSource>,
set_up_repo: Result<RepoOpen>,
insta_summary_redaction: Settings,
insta_tree_redaction: Settings,
) -> Result<()> {
// uncomment for logging output
// SimpleLogger::init(log::LevelFilter::Debug, Config::default())?;
@@ -93,35 +134,16 @@ fn test_backup_with_tar_gz_passes(
let first_snapshot = repo.backup(&opts, paths, SnapshotFile::default())?;

#[cfg(windows)]
assert_ron_snapshot!(
"backup-tar-summary-first-windows",
TestSummary(&first_snapshot),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!(
"backup-tar-summary-first-windows",
TestSummary(&first_snapshot)
);
});

#[cfg(not(windows))]
assert_ron_snapshot!("backup-tar-summary-first-nix",
TestSummary(&first_snapshot),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
insta_summary_redaction.bind(|| {
assert_ron_snapshot!("backup-tar-summary-first-nix", TestSummary(&first_snapshot));
});

assert_eq!(first_snapshot.parent, None);
@@ -133,24 +155,14 @@ fn test_backup_with_tar_gz_passes(
let tree: rustic_core::repofile::Tree = repo.get_tree(&tree.subtree.expect("Sub tree"))?;

#[cfg(windows)]
assert_ron_snapshot!(
"backup-tar-tree-windows",
tree,
{
".nodes[].ctime" => "[ctime]",
".nodes[].content" => "[content_id]",
}
);
insta_tree_redaction.bind(|| {
assert_ron_snapshot!("backup-tar-tree-windows", tree);
});

#[cfg(not(windows))]
assert_ron_snapshot!(
"backup-tar-tree-nix",
tree,
{
".nodes[].ctime" => "[ctime]",
".nodes[].content" => "[content_id]",
}
);
insta_tree_redaction.bind(|| {
assert_ron_snapshot!("backup-tar-tree-nix", tree);
});

// get all snapshots and check them
let all_snapshots = repo.get_all_snapshots()?;
@@ -164,37 +176,20 @@ fn test_backup_with_tar_gz_passes(
let second_snapshot = repo.backup(&opts, paths, SnapshotFile::default())?;

#[cfg(windows)]
assert_ron_snapshot!(
"backup-tar-summary-second-windows",
TestSummary(&second_snapshot),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!(
"backup-tar-summary-second-windows",
TestSummary(&second_snapshot)
);
});

#[cfg(not(windows))]
assert_ron_snapshot!(
"backup-tar-summary-second-nix",
TestSummary(&second_snapshot),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!(
"backup-tar-summary-second-nix",
TestSummary(&second_snapshot)
);
});

assert_eq!(second_snapshot.parent, Some(first_snapshot.id));
assert_eq!(first_snapshot.tree, second_snapshot.tree);
@@ -214,6 +209,8 @@ fn test_backup_with_tar_gz_passes(
fn test_backup_dry_run_with_tar_gz_passes(
tar_gz_testdata: Result<TestSource>,
set_up_repo: Result<RepoOpen>,
insta_summary_redaction: Settings,
insta_tree_redaction: Settings,
) -> Result<()> {
// Fixtures
let (source, repo) = (tar_gz_testdata?, set_up_repo?.to_indexed_ids()?);
@@ -229,35 +226,16 @@ fn test_backup_dry_run_with_tar_gz_passes(
let snap_dry_run = repo.backup(&opts, paths, SnapshotFile::default())?;

#[cfg(windows)]
assert_ron_snapshot!(
"dryrun-tar-summary-first-windows",
TestSummary(&snap_dry_run),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!(
"dryrun-tar-summary-first-windows",
TestSummary(&snap_dry_run)
);
});

#[cfg(not(windows))]
assert_ron_snapshot!("dryrun-tar-summary-first-nix",
TestSummary(&snap_dry_run),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
insta_summary_redaction.bind(|| {
assert_ron_snapshot!("dryrun-tar-summary-first-nix", TestSummary(&snap_dry_run));
});

// check that repo is still empty
@@ -279,24 +257,14 @@ fn test_backup_dry_run_with_tar_gz_passes(
let tree = repo.get_tree(&tree.subtree.expect("Sub tree"))?;

#[cfg(windows)]
assert_ron_snapshot!(
"dryrun-tar-tree-windows",
tree,
{
".nodes[].ctime" => "[ctime]",
".nodes[].content" => "[content_id]",
}
);
insta_tree_redaction.bind(|| {
assert_ron_snapshot!("dryrun-tar-tree-windows", tree);
});

#[cfg(not(windows))]
assert_ron_snapshot!(
"dryrun-tar-tree-nix",
tree,
{
".nodes[].ctime" => "[ctime]",
".nodes[].content" => "[content_id]",
}
);
insta_tree_redaction.bind(|| {
assert_ron_snapshot!("dryrun-tar-tree-nix", tree);
});

// re-read index
let repo = repo.to_indexed_ids()?;
@@ -305,37 +273,17 @@ fn test_backup_dry_run_with_tar_gz_passes(
let snap_dry_run = repo.backup(&opts, paths, SnapshotFile::default())?;

#[cfg(windows)]
assert_ron_snapshot!(
"dryrun-tar-summary-second-windows",
TestSummary(&snap_dry_run),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!(
"dryrun-tar-summary-second-windows",
TestSummary(&snap_dry_run)
);
});

#[cfg(not(windows))]
assert_ron_snapshot!("dryrun-tar-summary-second-nix",
TestSummary(&snap_dry_run),
{
".tree" => "[tree_id]",
".program_version" => "[version]",
".time" => "[time]",
".tags" => "[tags]",
".id" => "[id]",
".summary.backup_start" => "[backup_start]",
".summary.backup_end" => "[backup_end]",
".summary.backup_duration" => "[backup_duration]",
".summary.total_duration" => "[total_duration]",
}
);
insta_summary_redaction.bind(|| {
assert_ron_snapshot!("dryrun-tar-summary-second-nix", TestSummary(&snap_dry_run));
});

// check that no data has been added
let snaps = repo.get_all_snapshots()?;
Original file line number Diff line number Diff line change
@@ -24,15 +24,15 @@ TestSummary(SnapshotFile(
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: 18471,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 70,
tree_blobs: 6,
data_added: 1144124,
data_added_packed: 82916,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 78740,
data_added_trees: 18471,
data_added_trees_packed: 4176,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ expression: TestSummary(&second_snapshot)
TestSummary(SnapshotFile(
time: "[time]",
program_version: "[version]",
parent: Some(Id("7b7085ce125bcbbda8bcfcc1c8f7aa7b82a4e7f240efd5feaade6416dcb31c7e")),
parent: Some(Id("1e1c441c94bb94db891589deac182ac69d2cf2c8a434081e5608515553833cd1")),
tree: "[tree_id]",
paths: StringList([
"test",
@@ -25,15 +25,15 @@ TestSummary(SnapshotFile(
dirs_changed: 0,
dirs_unmodified: 6,
total_dirs_processed: 6,
total_dirsize_processed: 18471,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 0,
tree_blobs: 0,
data_added: 0,
data_added_packed: 0,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 0,
data_added_files_packed: 0,
data_added_trees: 0,
data_added_trees_packed: 0,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
Original file line number Diff line number Diff line change
@@ -24,15 +24,15 @@ TestSummary(SnapshotFile(
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 6,
total_dirsize_processed: 18465,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 70,
tree_blobs: 6,
data_added: 1144118,
data_added_packed: 82905,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 1125653,
data_added_files_packed: 78740,
data_added_trees: 18465,
data_added_trees_packed: 4165,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "",
backup_start: "[backup_start]",
backup_end: "[backup_end]",
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ expression: TestSummary(&snap_dry_run)
TestSummary(SnapshotFile(
time: "[time]",
program_version: "[version]",
parent: Some(Id("0c7ab572c3c7498fa3b941a9803ab950a52a846c2ad78579b3249af4508bf6c5")),
parent: Some(Id("f25b23c13b9c895d57d6017d466abe317b57b5db280c996d86ea1fe4db423743")),
tree: "[tree_id]",
paths: StringList([
"test",
@@ -25,15 +25,15 @@ TestSummary(SnapshotFile(
dirs_changed: 0,
dirs_unmodified: 6,
total_dirs_processed: 6,
total_dirsize_processed: 18465,
total_dirsize_processed: "[total_dirsize_processed]",
data_blobs: 0,
tree_blobs: 0,
data_added: 0,
data_added_packed: 0,
data_added: "[data_added]",
data_added_packed: "[data_added_packed]",
data_added_files: 0,
data_added_files_packed: 0,
data_added_trees: 0,
data_added_trees_packed: 0,
data_added_trees: "[data_added_trees]",
data_added_trees_packed: "[data_added_trees_packed]",
command: "",
backup_start: "[backup_start]",
backup_end: "[backup_end]",