@@ -36,7 +36,8 @@ use rstest::{fixture, rstest};
36
36
use rustic_core:: {
37
37
repofile:: SnapshotFile , BackupOptions , CheckOptions , ConfigOptions , FindMatches , FindNode ,
38
38
FullIndex , IndexedFull , IndexedStatus , KeyOptions , LimitOption , LsOptions , NoProgressBars ,
39
- OpenStatus , PathList , Repository , RepositoryBackends , RepositoryOptions , RusticResult ,
39
+ OpenStatus , ParentOptions , PathList , Repository , RepositoryBackends , RepositoryOptions ,
40
+ RusticResult , SnapshotGroupCriterion , SnapshotOptions , StringList ,
40
41
} ;
41
42
use rustic_core:: {
42
43
repofile:: { Metadata , Node } ,
@@ -98,36 +99,38 @@ fn handle_option(val: Content, _: ContentPath<'_>) -> String {
98
99
}
99
100
100
101
#[ fixture]
101
- fn insta_summary_redaction ( ) -> Settings {
102
+ fn insta_snapshotfile_redaction ( ) -> Settings {
102
103
let mut settings = Settings :: clone_current ( ) ;
103
104
104
- settings. add_redaction ( ".tree" , "[tree_id]" ) ;
105
- settings. add_dynamic_redaction ( ".program_version" , |val, _| {
105
+ settings. add_redaction ( ".**. tree" , "[tree_id]" ) ;
106
+ settings. add_dynamic_redaction ( ".**. program_version" , |val, _| {
106
107
val. resolve_inner ( )
107
108
. as_str ( )
108
109
. map_or ( "[program_version]" . to_string ( ) , |v| {
109
110
v. replace ( env ! ( "CARGO_PKG_VERSION" ) , "[rustic_core_version]" )
110
111
} )
111
112
} ) ;
112
- settings. add_redaction ( ".time" , "[time]" ) ;
113
- settings. add_dynamic_redaction ( ".parent" , handle_option) ;
114
- settings. add_redaction ( ".tags" , "[tags]" ) ;
115
- settings. add_redaction ( ".id" , "[id]" ) ;
116
- settings. add_redaction ( ".summary.backup_start" , "[backup_start]" ) ;
117
- settings. add_redaction ( ".summary.backup_end" , "[backup_end]" ) ;
118
- settings. add_redaction ( ".summary.backup_duration" , "[backup_duration]" ) ;
119
- settings. add_redaction ( ".summary.total_duration" , "[total_duration]" ) ;
120
- settings. add_redaction ( ".summary.data_added" , "[data_added]" ) ;
121
- settings. add_redaction ( ".summary.data_added_packed" , "[data_added_packed]" ) ;
113
+ settings. add_redaction ( ".**.time" , "[time]" ) ;
114
+ settings. add_dynamic_redaction ( ".**.parent" , handle_option) ;
115
+ settings. add_redaction ( ".**.id" , "[id]" ) ;
116
+ settings. add_redaction ( ".**.original" , "[original]" ) ;
117
+ settings. add_redaction ( ".**.hostname" , "[hostname]" ) ;
118
+ settings. add_redaction ( ".**.command" , "[command]" ) ;
119
+ settings. add_redaction ( ".**.summary.backup_start" , "[backup_start]" ) ;
120
+ settings. add_redaction ( ".**.summary.backup_end" , "[backup_end]" ) ;
121
+ settings. add_redaction ( ".**.summary.backup_duration" , "[backup_duration]" ) ;
122
+ settings. add_redaction ( ".**.summary.total_duration" , "[total_duration]" ) ;
123
+ settings. add_redaction ( ".**.summary.data_added" , "[data_added]" ) ;
124
+ settings. add_redaction ( ".**.summary.data_added_packed" , "[data_added_packed]" ) ;
122
125
settings. add_redaction (
123
- ".summary.total_dirsize_processed" ,
126
+ ".**. summary.total_dirsize_processed" ,
124
127
"[total_dirsize_processed]" ,
125
128
) ;
126
129
settings. add_redaction (
127
- ".summary.data_added_trees_packed" ,
130
+ ".**. summary.data_added_trees_packed" ,
128
131
"[data_added_trees_packed]" ,
129
132
) ;
130
- settings. add_redaction ( ".summary.data_added_trees" , "[data_added_trees]" ) ;
133
+ settings. add_redaction ( ".**. summary.data_added_trees" , "[data_added_trees]" ) ;
131
134
132
135
settings
133
136
}
@@ -176,7 +179,7 @@ fn assert_with_win<T: Serialize>(test: &str, snap: T) {
176
179
fn test_backup_with_tar_gz_passes (
177
180
tar_gz_testdata : Result < TestSource > ,
178
181
set_up_repo : Result < RepoOpen > ,
179
- insta_summary_redaction : Settings ,
182
+ insta_snapshotfile_redaction : Settings ,
180
183
insta_node_redaction : Settings ,
181
184
) -> Result < ( ) > {
182
185
// uncomment for logging output
@@ -196,7 +199,7 @@ fn test_backup_with_tar_gz_passes(
196
199
// We can also bind to scope ( https://docs.rs/insta/latest/insta/struct.Settings.html#method.bind_to_scope )
197
200
// But I think that can get messy with a lot of tests, also checking which settings are currently applied
198
201
// will be probably harder
199
- insta_summary_redaction . bind ( || {
202
+ insta_snapshotfile_redaction . bind ( || {
200
203
assert_with_win ( "backup-tar-summary-first" , & first_snapshot) ;
201
204
} ) ;
202
205
@@ -223,21 +226,43 @@ fn test_backup_with_tar_gz_passes(
223
226
// second backup
224
227
let second_snapshot = repo. backup ( & opts, paths, SnapshotFile :: default ( ) ) ?;
225
228
226
- insta_summary_redaction . bind ( || {
229
+ insta_snapshotfile_redaction . bind ( || {
227
230
assert_with_win ( "backup-tar-summary-second" , & second_snapshot) ;
228
231
} ) ;
229
232
230
233
assert_eq ! ( second_snapshot. parent, Some ( first_snapshot. id) ) ;
231
234
assert_eq ! ( first_snapshot. tree, second_snapshot. tree) ;
232
235
236
+ // pack files should be unchanged
237
+ let packs2: Vec < _ > = repo. list ( rustic_core:: FileType :: Pack ) ?. collect ( ) ;
238
+ assert_eq ! ( packs1, packs2) ;
239
+
240
+ // re-read index
241
+ let repo = repo. to_indexed_ids ( ) ?;
242
+ // third backup with tags and explicitely given parent
243
+ let snap = SnapshotOptions :: default ( )
244
+ . tag ( [ StringList :: from_str ( "a,b" ) ?] )
245
+ . to_snapshot ( ) ?;
246
+ let opts = opts. parent_opts ( ParentOptions :: default ( ) . parent ( second_snapshot. id . to_string ( ) ) ) ;
247
+ let third_snapshot = repo. backup ( & opts, paths, snap) ?;
248
+
249
+ insta_snapshotfile_redaction. bind ( || {
250
+ assert_with_win ( "backup-tar-summary-third" , & third_snapshot) ;
251
+ } ) ;
252
+ assert_eq ! ( third_snapshot. parent, Some ( second_snapshot. id) ) ;
253
+ assert_eq ! ( third_snapshot. tree, second_snapshot. tree) ;
254
+
233
255
// get all snapshots and check them
234
256
let mut all_snapshots = repo. get_all_snapshots ( ) ?;
235
257
all_snapshots. sort_unstable ( ) ;
236
- assert_eq ! ( vec![ first_snapshot, second_snapshot] , all_snapshots) ;
258
+ assert_eq ! (
259
+ vec![ first_snapshot, second_snapshot, third_snapshot] ,
260
+ all_snapshots
261
+ ) ;
237
262
238
263
// pack files should be unchanged
239
- let packs2 : Vec < _ > = repo. list ( rustic_core:: FileType :: Pack ) ?. collect ( ) ;
240
- assert_eq ! ( packs1, packs2 ) ;
264
+ let packs3 : Vec < _ > = repo. list ( rustic_core:: FileType :: Pack ) ?. collect ( ) ;
265
+ assert_eq ! ( packs1, packs3 ) ;
241
266
242
267
// Check if snapshots can be retrieved
243
268
let mut ids: Vec < _ > = all_snapshots. iter ( ) . map ( |sn| sn. id . to_string ( ) ) . collect ( ) ;
@@ -250,14 +275,33 @@ fn test_backup_with_tar_gz_passes(
250
275
let snaps = repo. get_snapshots ( & ids) ?;
251
276
assert_eq ! ( snaps, all_snapshots) ;
252
277
278
+ // get snapshot group
279
+ let group_by = SnapshotGroupCriterion :: new ( ) . tags ( true ) ;
280
+ let mut groups = repo. get_snapshot_group ( & [ ] , group_by, |_| true ) ?;
281
+
282
+ // sort groups to get unique result
283
+ groups. iter_mut ( ) . for_each ( |( _, snaps) | snaps. sort ( ) ) ;
284
+ groups. sort_by_key ( |( group, _) | group. tags . clone ( ) ) ;
285
+
286
+ insta_snapshotfile_redaction. bind ( || {
287
+ assert_with_win ( "backup-tar-groups" , & groups) ;
288
+ } ) ;
289
+
290
+ // filter snapshots by tag
291
+ let filter = |snap : & SnapshotFile | snap. tags . contains ( "a" ) ;
292
+ let snaps = repo. get_matching_snapshots ( filter) ?;
293
+ insta_snapshotfile_redaction. bind ( || {
294
+ assert_with_win ( "backup-tar-matching-snaps" , & snaps) ;
295
+ } ) ;
296
+
253
297
Ok ( ( ) )
254
298
}
255
299
256
300
#[ rstest]
257
301
fn test_backup_dry_run_with_tar_gz_passes (
258
302
tar_gz_testdata : Result < TestSource > ,
259
303
set_up_repo : Result < RepoOpen > ,
260
- insta_summary_redaction : Settings ,
304
+ insta_snapshotfile_redaction : Settings ,
261
305
insta_node_redaction : Settings ,
262
306
) -> Result < ( ) > {
263
307
// Fixtures
@@ -273,7 +317,7 @@ fn test_backup_dry_run_with_tar_gz_passes(
273
317
// dry-run backup
274
318
let snap_dry_run = repo. backup ( & opts, paths, SnapshotFile :: default ( ) ) ?;
275
319
276
- insta_summary_redaction . bind ( || {
320
+ insta_snapshotfile_redaction . bind ( || {
277
321
assert_with_win ( "dryrun-tar-summary-first" , & snap_dry_run) ;
278
322
} ) ;
279
323
@@ -305,7 +349,7 @@ fn test_backup_dry_run_with_tar_gz_passes(
305
349
let opts = opts. dry_run ( true ) ;
306
350
let snap_dry_run = repo. backup ( & opts, paths, SnapshotFile :: default ( ) ) ?;
307
351
308
- insta_summary_redaction . bind ( || {
352
+ insta_snapshotfile_redaction . bind ( || {
309
353
assert_with_win ( "dryrun-tar-summary-second" , & snap_dry_run) ;
310
354
} ) ;
311
355
0 commit comments