spring-batch-rs 0.3.4

A toolkit for building enterprise-grade batch applications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
//! # ZIP Tasklet Integration Tests
//!
//! This module contains comprehensive integration tests for the ZIP tasklet functionality.
//! It tests various scenarios including basic compression, file filtering, directory structure
//! preservation, error handling, and integration with Spring Batch job execution.

pub mod common;

use std::{
    fs::{self, File},
    io::{Read, Write},
    path::Path,
};

use spring_batch_rs::{
    core::{
        job::{Job, JobBuilder},
        step::{StepBuilder, StepStatus},
    },
    tasklet::zip::ZipTaskletBuilder,
};
use tempfile::TempDir;
use zip::ZipArchive;

/// Helper function to create a comprehensive test directory structure
fn create_test_directory_structure(base_dir: &Path) -> Result<(), std::io::Error> {
    // Create main directories
    let data_dir = base_dir.join("data");
    let logs_dir = base_dir.join("logs");
    let temp_dir = base_dir.join("temp");
    let docs_dir = data_dir.join("documents");
    let config_dir = data_dir.join("config");
    let nested_dir = docs_dir.join("nested");

    fs::create_dir_all(&data_dir)?;
    fs::create_dir_all(&logs_dir)?;
    fs::create_dir_all(&temp_dir)?;
    fs::create_dir_all(&docs_dir)?;
    fs::create_dir_all(&config_dir)?;
    fs::create_dir_all(&nested_dir)?;

    // Create test files with various extensions and content
    let test_files = vec![
        // Root level files
        (
            base_dir.join("readme.txt"),
            "This is a README file\nWith multiple lines\nAnd some content.",
        ),
        (
            base_dir.join("license.md"),
            "# License\n\nMIT License\n\nCopyright (c) 2024",
        ),
        // Data directory files
        (
            data_dir.join("data.csv"),
            "name,age,city\nJohn,30,New York\nJane,25,Los Angeles\nBob,35,Chicago",
        ),
        (
            data_dir.join("info.txt"),
            "Important information about the data processing.",
        ),
        (
            data_dir.join("backup.bak"),
            "Backup file content that should be preserved.",
        ),
        // Documents directory files
        (
            docs_dir.join("manual.txt"),
            "User Manual\n============\n\n1. Getting Started\n2. Configuration\n3. Advanced Usage",
        ),
        (
            docs_dir.join("guide.md"),
            "# User Guide\n\n## Introduction\nThis is a comprehensive guide.",
        ),
        (
            docs_dir.join("notes.txt"),
            "Development notes and important reminders.",
        ),
        // Nested directory files
        (
            nested_dir.join("deep.txt"),
            "This file is deeply nested in the directory structure.",
        ),
        (
            nested_dir.join("config.json"),
            r#"{"setting": "value", "enabled": true}"#,
        ),
        // Config directory files
        (
            config_dir.join("app.properties"),
            "app.name=TestApp\napp.version=1.0.0\ndebug=true",
        ),
        (
            config_dir.join("database.json"),
            r#"{"host": "localhost", "port": 5432, "database": "test"}"#,
        ),
        // Log files
        (
            logs_dir.join("application.log"),
            "2024-01-01 10:00:00 INFO Application started\n2024-01-01 10:01:00 INFO Processing data\n2024-01-01 10:02:00 INFO Processing completed",
        ),
        (
            logs_dir.join("error.log"),
            "2024-01-01 10:01:30 ERROR Database connection failed\n2024-01-01 10:01:35 ERROR Retrying connection",
        ),
        (
            logs_dir.join("debug.log"),
            "2024-01-01 10:00:01 DEBUG Initializing components\n2024-01-01 10:00:02 DEBUG Loading configuration",
        ),
        (
            logs_dir.join("access.log"),
            "127.0.0.1 - - [01/Jan/2024:10:00:00 +0000] \"GET / HTTP/1.1\" 200 1234",
        ),
        // Temporary files (should be excluded in some tests)
        (
            temp_dir.join("cache.tmp"),
            "Temporary cache data that should be excluded in filtered tests",
        ),
        (temp_dir.join("session.tmp"), "Temporary session data"),
        (temp_dir.join("processing.tmp"), "Temporary processing file"),
    ];

    for (file_path, content) in test_files {
        let mut file = File::create(&file_path)?;
        file.write_all(content.as_bytes())?;
    }

    Ok(())
}

/// Helper function to verify ZIP archive contents
fn verify_zip_contents(
    zip_path: &Path,
    expected_files: &[&str],
) -> Result<(), Box<dyn std::error::Error>> {
    let file = File::open(zip_path)?;
    let mut archive = ZipArchive::new(file)?;

    let mut found_files: Vec<String> = Vec::new();
    for i in 0..archive.len() {
        let file = archive.by_index(i)?;
        found_files.push(file.name().to_string());
    }

    // Sort both vectors for comparison
    let mut expected_sorted = expected_files.to_vec();
    expected_sorted.sort();
    found_files.sort();

    assert_eq!(
        found_files.len(),
        expected_sorted.len(),
        "Expected {} files, found {}: {:?}",
        expected_sorted.len(),
        found_files.len(),
        found_files
    );

    for expected in expected_sorted {
        assert!(
            found_files.contains(&expected.to_string()),
            "Expected file '{}' not found in archive. Found files: {:?}",
            expected,
            found_files
        );
    }

    Ok(())
}

/// Helper function to count files in ZIP archive
fn count_zip_files(zip_path: &Path) -> Result<usize, Box<dyn std::error::Error>> {
    let file = File::open(zip_path)?;
    let archive = ZipArchive::new(file)?;
    Ok(archive.len())
}

/// Helper function to verify file content in ZIP archive
fn verify_file_content_in_zip(
    zip_path: &Path,
    file_name: &str,
    expected_content: &str,
) -> Result<(), Box<dyn std::error::Error>> {
    let file = File::open(zip_path)?;
    let mut archive = ZipArchive::new(file)?;

    let mut zip_file = archive.by_name(file_name)?;
    let mut content = String::new();
    zip_file.read_to_string(&mut content)?;

    assert_eq!(
        content, expected_content,
        "File content mismatch for '{}'",
        file_name
    );
    Ok(())
}

#[test]
fn test_basic_directory_compression() {
    let temp_dir = TempDir::new().unwrap();
    let source_dir = temp_dir.path().join("source");
    let target_zip = temp_dir.path().join("archive.zip");

    // Create test directory structure
    create_test_directory_structure(&source_dir).unwrap();

    // Create ZIP tasklet
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&source_dir)
        .target_path(&target_zip)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-directory-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify ZIP contains expected files
    let file_count = count_zip_files(&target_zip).unwrap();
    assert!(
        file_count > 15,
        "Should contain multiple files, found: {}",
        file_count
    );

    // Verify some specific files exist in the archive
    verify_file_content_in_zip(
        &target_zip,
        "readme.txt",
        "This is a README file\nWith multiple lines\nAnd some content.",
    )
    .unwrap();
    verify_file_content_in_zip(
        &target_zip,
        "data/data.csv",
        "name,age,city\nJohn,30,New York\nJane,25,Los Angeles\nBob,35,Chicago",
    )
    .unwrap();
}

#[test]
fn test_single_file_compression() {
    let temp_dir = TempDir::new().unwrap();
    let source_file = temp_dir.path().join("test.txt");
    let target_zip = temp_dir.path().join("single_file.zip");

    // Create test file
    fs::write(
        &source_file,
        "Hello, World!\nThis is a test file for single file compression.",
    )
    .unwrap();

    // Create ZIP tasklet
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&source_file)
        .target_path(&target_zip)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-single-file-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify ZIP contains exactly one file
    let file_count = count_zip_files(&target_zip).unwrap();
    assert_eq!(file_count, 1, "Should contain exactly one file");

    // Verify file content
    verify_file_content_in_zip(
        &target_zip,
        "test.txt",
        "Hello, World!\nThis is a test file for single file compression.",
    )
    .unwrap();
}

#[test]
fn test_compression_with_include_pattern() {
    let temp_dir = TempDir::new().unwrap();
    let source_dir = temp_dir.path().join("source");
    let target_zip = temp_dir.path().join("txt_files.zip");

    // Create test directory structure
    create_test_directory_structure(&source_dir).unwrap();

    // Create ZIP tasklet with include pattern for .txt files only
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&source_dir)
        .target_path(&target_zip)
        .include_pattern("*.txt")
        .compression_level(9)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-txt-files-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify only .txt files are included
    let expected_txt_files = vec![
        "readme.txt",
        "data/info.txt",
        "data/documents/manual.txt",
        "data/documents/notes.txt",
        "data/documents/nested/deep.txt",
    ];

    verify_zip_contents(&target_zip, &expected_txt_files).unwrap();
}

#[test]
fn test_compression_with_exclude_pattern() {
    let temp_dir = TempDir::new().unwrap();
    let source_dir = temp_dir.path().join("source");
    let target_zip = temp_dir.path().join("no_tmp_files.zip");

    // Create test directory structure
    create_test_directory_structure(&source_dir).unwrap();

    // Create ZIP tasklet with exclude pattern for .tmp files
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&source_dir)
        .target_path(&target_zip)
        .exclude_pattern("*.tmp")
        .compression_level(6)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-no-tmp-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify .tmp files are excluded
    let file = File::open(&target_zip).unwrap();
    let mut archive = ZipArchive::new(file).unwrap();

    for i in 0..archive.len() {
        let file = archive.by_index(i).unwrap();
        assert!(
            !file.name().ends_with(".tmp"),
            "Found .tmp file in archive: {}",
            file.name()
        );
    }

    // Should still contain other files
    let file_count = count_zip_files(&target_zip).unwrap();
    assert!(
        file_count > 10,
        "Should contain multiple non-tmp files, found: {}",
        file_count
    );
}

#[test]
fn test_compression_with_flattened_structure() {
    let temp_dir = TempDir::new().unwrap();
    let source_dir = temp_dir.path().join("source");
    let target_zip = temp_dir.path().join("flattened.zip");

    // Create test directory structure
    create_test_directory_structure(&source_dir).unwrap();

    // Create ZIP tasklet with flattened structure
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&source_dir)
        .target_path(&target_zip)
        .preserve_structure(false)
        .compression_level(3)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-flattened-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify all files are at root level (no directory separators)
    let file = File::open(&target_zip).unwrap();
    let mut archive = ZipArchive::new(file).unwrap();

    for i in 0..archive.len() {
        let file = archive.by_index(i).unwrap();
        assert!(
            !file.name().contains('/'),
            "Found file with directory structure: {}",
            file.name()
        );
    }
}

#[test]
fn test_multi_step_job_with_zip_tasklets() {
    let temp_dir = TempDir::new().unwrap();
    let source_dir = temp_dir.path().join("source");
    let logs_zip = temp_dir.path().join("logs.zip");
    let docs_zip = temp_dir.path().join("docs.zip");
    let data_zip = temp_dir.path().join("data.zip");

    // Create test directory structure
    create_test_directory_structure(&source_dir).unwrap();

    // Create multiple ZIP tasklets for different directories
    let logs_tasklet = ZipTaskletBuilder::new()
        .source_path(source_dir.join("logs"))
        .target_path(&logs_zip)
        .include_pattern("*.log")
        .compression_level(9)
        .build()
        .unwrap();

    let docs_tasklet = ZipTaskletBuilder::new()
        .source_path(source_dir.join("data").join("documents"))
        .target_path(&docs_zip)
        .compression_level(6)
        .build()
        .unwrap();

    let data_tasklet = ZipTaskletBuilder::new()
        .source_path(source_dir.join("data"))
        .target_path(&data_zip)
        .exclude_pattern("documents/**")
        .compression_level(3)
        .build()
        .unwrap();

    // Create steps
    let logs_step = StepBuilder::new("zip-logs-step")
        .tasklet(&logs_tasklet)
        .build();

    let docs_step = StepBuilder::new("zip-docs-step")
        .tasklet(&docs_tasklet)
        .build();

    let data_step = StepBuilder::new("zip-data-step")
        .tasklet(&data_tasklet)
        .build();

    // Create multi-step job
    let job = JobBuilder::new()
        .start(&logs_step)
        .next(&docs_step)
        .next(&data_step)
        .build();

    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");

    // Verify all ZIP files were created
    assert!(logs_zip.exists(), "Logs ZIP should be created");
    assert!(docs_zip.exists(), "Docs ZIP should be created");
    assert!(data_zip.exists(), "Data ZIP should be created");

    // Verify step executions
    let logs_execution = job.get_step_execution("zip-logs-step").unwrap();
    let docs_execution = job.get_step_execution("zip-docs-step").unwrap();
    let data_execution = job.get_step_execution("zip-data-step").unwrap();

    assert_eq!(logs_execution.status, StepStatus::Success);
    assert_eq!(docs_execution.status, StepStatus::Success);
    assert_eq!(data_execution.status, StepStatus::Success);

    // Verify logs ZIP contains only .log files
    let logs_file_count = count_zip_files(&logs_zip).unwrap();
    assert_eq!(logs_file_count, 4, "Logs ZIP should contain 4 .log files");

    // Verify docs ZIP contains documentation files
    let docs_file_count = count_zip_files(&docs_zip).unwrap();
    assert!(
        docs_file_count >= 3,
        "Docs ZIP should contain at least 3 files"
    );
}

#[test]
fn test_error_handling_nonexistent_source() {
    let temp_dir = TempDir::new().unwrap();
    let nonexistent_source = temp_dir.path().join("nonexistent");
    let target_zip = temp_dir.path().join("should_not_be_created.zip");

    // Try to create ZIP tasklet with nonexistent source
    let result = ZipTaskletBuilder::new()
        .source_path(&nonexistent_source)
        .target_path(&target_zip)
        .build();
    assert!(result.is_err(), "Should fail with nonexistent source");

    // Verify ZIP file was not created
    assert!(
        !target_zip.exists(),
        "ZIP file should not be created on error"
    );
}

#[test]
fn test_error_handling_invalid_target_directory() {
    let temp_dir = TempDir::new().unwrap();
    let source_file = temp_dir.path().join("test.txt");

    // Create source file
    fs::write(&source_file, "test content").unwrap();

    // Try to create ZIP in a directory that cannot be created (using a file as directory)
    let invalid_target = source_file.join("invalid").join("target.zip");

    let result = ZipTaskletBuilder::new()
        .source_path(&source_file)
        .target_path(&invalid_target)
        .build();
    assert!(result.is_err(), "Should fail with invalid target directory");
}

#[test]
fn test_builder_validation() {
    // Test missing source path
    let result = ZipTaskletBuilder::new()
        .target_path("/tmp/test.zip")
        .build();
    assert!(result.is_err(), "Should fail without source path");

    // Test missing target path
    let result = ZipTaskletBuilder::new().source_path("/tmp/source").build();
    assert!(result.is_err(), "Should fail without target path");

    // Test both missing
    let result = ZipTaskletBuilder::new().build();
    assert!(result.is_err(), "Should fail without both paths");
}

#[test]
fn test_empty_directory_compression() {
    let temp_dir = TempDir::new().unwrap();
    let empty_source = temp_dir.path().join("empty");
    let target_zip = temp_dir.path().join("empty.zip");

    // Create empty directory
    fs::create_dir(&empty_source).unwrap();

    // Create ZIP tasklet
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&empty_source)
        .target_path(&target_zip)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-empty-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(
        target_zip.exists(),
        "ZIP file should be created even for empty directory"
    );

    // Verify ZIP is empty or contains only directory entries
    let file_count = count_zip_files(&target_zip).unwrap();
    assert_eq!(file_count, 0, "Empty directory should produce empty ZIP");
}

#[test]
fn test_large_file_compression() {
    let temp_dir = TempDir::new().unwrap();
    let large_file = temp_dir.path().join("large.txt");
    let target_zip = temp_dir.path().join("large.zip");

    // Create a large file (1MB of repeated content)
    let large_content =
        "This is a line of text that will be repeated many times to create a large file.\n"
            .repeat(10000);
    fs::write(&large_file, &large_content).unwrap();

    // Create ZIP tasklet with maximum compression
    let zip_tasklet = ZipTaskletBuilder::new()
        .source_path(&large_file)
        .target_path(&target_zip)
        .compression_level(9)
        .build()
        .unwrap();

    // Create and execute step
    let step = StepBuilder::new("zip-large-file-step")
        .tasklet(&zip_tasklet)
        .build();

    let job = JobBuilder::new().start(&step).build();
    let result = job.run();

    // Verify job execution
    assert!(result.is_ok(), "Job should complete successfully");
    assert!(target_zip.exists(), "ZIP file should be created");

    // Verify compression was effective
    let original_size = fs::metadata(&large_file).unwrap().len();
    let compressed_size = fs::metadata(&target_zip).unwrap().len();

    assert!(
        compressed_size < original_size,
        "Compressed size ({} bytes) should be less than original ({} bytes)",
        compressed_size,
        original_size
    );

    // For repetitive content, compression should be very effective
    let compression_ratio = compressed_size as f64 / original_size as f64;
    assert!(
        compression_ratio < 0.1,
        "Compression ratio should be less than 10% for repetitive content, got {:.2}%",
        compression_ratio * 100.0
    );
}

#[test]
fn test_compression_levels() {
    let temp_dir = TempDir::new().unwrap();
    let source_file = temp_dir.path().join("large_test.txt");

    // Create a larger file for better compression testing
    let large_content = "This is a test file with repeated content. ".repeat(1000);
    fs::write(&source_file, &large_content).unwrap();

    // Test different compression levels
    let compression_levels = vec![0, 3, 6, 9];
    let mut zip_sizes = Vec::new();

    for level in compression_levels {
        let target_zip = temp_dir
            .path()
            .join(format!("compressed_level_{}.zip", level));

        let zip_tasklet = ZipTaskletBuilder::new()
            .source_path(&source_file)
            .target_path(&target_zip)
            .compression_level(level)
            .build()
            .unwrap();

        let step = StepBuilder::new(&format!("zip-level-{}-step", level))
            .tasklet(&zip_tasklet)
            .build();

        let job = JobBuilder::new().start(&step).build();
        let result = job.run();

        if let Err(ref e) = result {
            eprintln!("Job failed for level {}: {:?}", level, e);
        }
        assert!(
            result.is_ok(),
            "Job should complete successfully for level {}",
            level
        );
        assert!(
            target_zip.exists(),
            "ZIP file should be created for level {}",
            level
        );

        let zip_size = fs::metadata(&target_zip).unwrap().len();
        zip_sizes.push((level, zip_size));
    }

    // Verify that higher compression levels generally produce smaller files
    // (though this might not always be true for very small files)
    let level_0_size = zip_sizes.iter().find(|(level, _)| *level == 0).unwrap().1;
    let level_9_size = zip_sizes.iter().find(|(level, _)| *level == 9).unwrap().1;

    // Level 9 should be smaller or equal to level 0 for repetitive content
    assert!(
        level_9_size <= level_0_size,
        "Level 9 compression ({} bytes) should be <= level 0 ({} bytes)",
        level_9_size,
        level_0_size
    );
}