Skip to content

Commit

Permalink
Add json support to gui (#1083)
Browse files Browse the repository at this point in the history
* Add json support to gui

* Cli support

* Tests

* Zip fixed

* Always printing

* Zip

* Bound

* Improved CI

* More tests

* Maybe

* Different duplicate delete
  • Loading branch information
qarmin authored Oct 12, 2023
1 parent 9b57382 commit 0462324
Show file tree
Hide file tree
Showing 24 changed files with 909 additions and 452 deletions.
75 changes: 7 additions & 68 deletions .github/workflows/linux_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,73 +38,12 @@ jobs:
path: target/release/czkawka_cli
if: ${{ matrix.type == 'release' }}

# Duplicate finder checks included and excluded directories
# Others are just check delete files number
- name: Linux Regression Test
run: |
wget https://github.com/qarmin/czkawka/releases/download/1.1.0/TestSuite.zip
unzip TestSuite.zip -d TestSuite
python3 misc/check_results.py TestSuite 15 8
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -D aen -m 1024
python3 misc/check_results.py TestSuite 7 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -D aen -m 1024
python3 misc/check_results.py TestSuite 7 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -x TEXT -D aeo -m 1024
python3 misc/check_results.py TestSuite 14 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -e "$(pwd)/TestSuite/SubFolder" -D aeo -m 1024
python3 misc/check_results.py TestSuite 13 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -m 1500 -D aeo
python3 misc/check_results.py TestSuite 8 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -R -m 1024
python3 misc/check_results.py TestSuite 15 8
target/release/czkawka_cli dup -d "$(pwd)/TestSuite" -R -D aeo -m 1024
python3 misc/check_results.py TestSuite 13 8
target/release/czkawka_cli big -d "$(pwd)/TestSuite"
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli empty-files -d "$(pwd)/TestSuite"
python3 misc/check_results.py TestSuite 15 8
target/release/czkawka_cli empty-files -d "$(pwd)/TestSuite" -D
python3 misc/check_results.py TestSuite 13 8
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli empty-folders -d "$(pwd)/TestSuite"
python3 misc/check_results.py TestSuite 15 8
target/release/czkawka_cli empty-folders -d "$(pwd)/TestSuite" -D
python3 misc/check_results.py TestSuite 15 2
rm -rf TestSuite
unzip TestSuite.zip -d TestSuite
target/release/czkawka_cli temp -d "$(pwd)/TestSuite"
python3 misc/check_results.py TestSuite 15 8
target/release/czkawka_cli temp -d "$(pwd)/TestSuite" -D
python3 misc/check_results.py TestSuite 14 8
wget https://github.com/qarmin/czkawka/releases/download/6.0.0/TestFiles.zip
cd ci_tester
cargo build --release
cd ..
ci_tester/target/release/ci_tester target/release/czkawka_cli
if: ${{ matrix.type == 'release' }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ flatpak/
*.profdata
/lcov_report*
/report
ci_tester/target
ci_tester/Cargo.lock
czkawka_slint_gui/Cargo.lock
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ members = [
"czkawka_core",
"czkawka_cli",
"czkawka_gui",
# "czkawka_slint_gui",
]
exclude = [
"ci_tester",
"czkawka_slint_gui"
]
resolver = "2"
Expand Down
11 changes: 11 additions & 0 deletions ci_tester/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "ci_tester"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
state = "0.6.0"
handsome_logger = "0.8.0"
log = "0.4.20"
233 changes: 233 additions & 0 deletions ci_tester/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
use log::info;
use std::collections::BTreeSet;
use std::fs;
use std::process::Command;
use std::process::Stdio;

#[derive(Default, Clone, Debug)]
struct CollectedFiles {
files: BTreeSet<String>,
folders: BTreeSet<String>,
symlinks: BTreeSet<String>,
}

static CZKAWKA_PATH: state::InitCell<String> = state::InitCell::new();
static COLLECTED_FILES: state::InitCell<CollectedFiles> = state::InitCell::new();

const ATTEMPTS: u32 = 10;

// App runs - ./ci_tester PATH_TO_CZKAWKA
fn main() {
handsome_logger::init().unwrap();
let args: Vec<String> = std::env::args().collect();
let path_to_czkawka = args[1].clone();
CZKAWKA_PATH.set(path_to_czkawka);
remove_test_dir();
run_with_good_status(&["ls"], false);
unzip_files();

let all_files = collect_all_files_and_dirs("TestFiles").unwrap();
COLLECTED_FILES.set(all_files);
remove_test_dir();

for _ in 0..ATTEMPTS {
test_empty_files();
test_smallest_files();
test_biggest_files();
test_empty_folders();
test_temporary_files();
test_symlinks_files();
test_remove_duplicates_one_oldest();
test_remove_duplicates_one_newest();
test_remove_duplicates_all_expect_newest();
test_remove_duplicates_all_expect_oldest();
}

println!("Completed checking");
}
fn test_remove_duplicates_all_expect_oldest() {
info!("test_remove_duplicates_all_expect_oldest");
run_test(
&["dup", "-d", "TestFiles", "-D", "AEO"],
vec!["Images/A1.jpg", "Images/A5.jpg", "Music/M1.mp3", "Music/M2.mp3", "Videos/V1.mp4", "Videos/V5.mp4"],
vec![],
vec![],
);
}
fn test_remove_duplicates_all_expect_newest() {
info!("test_remove_duplicates_all_expect_newest");
run_test(
&["dup", "-d", "TestFiles", "-D", "AEN"],
vec!["Images/A2.jpg", "Images/A5.jpg", "Music/M1.mp3", "Music/M5.mp3", "Videos/V1.mp4", "Videos/V2.mp4"],
vec![],
vec![],
);
}

fn test_remove_duplicates_one_newest() {
info!("test_remove_duplicates_one_newest");
run_test(
&["dup", "-d", "TestFiles", "-D", "ON"],
vec!["Images/A1.jpg", "Music/M2.mp3", "Videos/V5.mp4"],
vec![],
vec![],
);
}
fn test_remove_duplicates_one_oldest() {
info!("test_remove_duplicates_one_oldest");
run_test(
&["dup", "-d", "TestFiles", "-D", "OO"],
vec!["Images/A2.jpg", "Music/M5.mp3", "Videos/V2.mp4"],
vec![],
vec![],
);
}

fn test_symlinks_files() {
info!("test_symlinks_files");
run_test(&["symlinks", "-d", "TestFiles", "-D"], vec![], vec![], vec!["Symlinks/EmptyFiles"]);
}
fn test_temporary_files() {
info!("test_temporary_files");
run_test(&["temp", "-d", "TestFiles", "-D"], vec!["Temporary/Boczze.cache"], vec![], vec![]);
}
fn test_empty_folders() {
info!("test_empty_folders");
run_test(
&["empty-folders", "-d", "TestFiles", "-D"],
vec![],
vec!["EmptyFolders/One", "EmptyFolders/Two", "EmptyFolders/Two/TwoInside"],
vec![],
);
}

fn test_biggest_files() {
info!("test_biggest_files");
run_test(
&["big", "-d", "TestFiles", "-n", "6", "-D"],
vec!["Music/M3.flac", "Music/M4.mp3", "Videos/V2.mp4", "Videos/V3.webm", "Videos/V1.mp4", "Videos/V5.mp4"],
vec![],
vec![],
);
}

fn test_smallest_files() {
info!("test_smallest_files");
run_test(
&["big", "-d", "TestFiles", "-J", "-n", "5", "-D"],
vec!["Broken/Br.jpg", "Broken/Br.mp3", "Broken/Br.pdf", "Broken/Br.zip", "EmptyFolders/ThreeButNot/KEKEKE"],
vec![],
vec![],
);
}

fn test_empty_files() {
info!("test_empty_files");
run_test(&["empty-files", "-d", "TestFiles", "-D"], vec!["EmptyFile"], vec![], vec![]);
}

////////////////////////////////////
////////////////////////////////////
/////////HELPER FUNCTIONS///////////
////////////////////////////////////
////////////////////////////////////

fn run_test(arguments: &[&str], expected_files_differences: Vec<&'static str>, expected_folders_differences: Vec<&'static str>, expected_symlinks_differences: Vec<&'static str>) {
unzip_files();
// Add path_to_czkawka to arguments
let mut all_arguments = vec![];
all_arguments.push(CZKAWKA_PATH.get().as_str());
all_arguments.extend_from_slice(arguments);
run_with_good_status(&all_arguments, true);
file_folder_diffs(
COLLECTED_FILES.get(),
expected_files_differences,
expected_folders_differences,
expected_symlinks_differences,
);

remove_test_dir();
}
fn unzip_files() {
run_with_good_status(&["unzip", "-X", "TestFiles.zip", "-d", "TestFiles"], false);
}
fn remove_test_dir() {
let _ = fs::remove_dir_all("TestFiles");
}

fn run_with_good_status(str_command: &[&str], print_messages: bool) {
let mut command = Command::new(str_command[0]);
let mut com = command.args(&str_command[1..]);
if !print_messages {
com = com.stderr(Stdio::piped()).stdout(Stdio::piped());
}
let status = com.spawn().expect("failed to execute process").wait().unwrap();
assert!(status.success());
}

fn file_folder_diffs(
all_files: &CollectedFiles,
mut expected_files_differences: Vec<&'static str>,
mut expected_folders_differences: Vec<&'static str>,
mut expected_symlinks_differences: Vec<&'static str>,
) {
let current_files = collect_all_files_and_dirs("TestFiles").unwrap();
let mut diff_files = all_files
.files
.difference(&current_files.files)
.map(|e| e.strip_prefix("TestFiles/").unwrap().to_string())
.collect::<Vec<_>>();
let mut diff_folders = all_files
.folders
.difference(&current_files.folders)
.map(|e| e.strip_prefix("TestFiles/").unwrap().to_string())
.collect::<Vec<_>>();
let mut diff_symlinks = all_files
.symlinks
.difference(&current_files.symlinks)
.map(|e| e.strip_prefix("TestFiles/").unwrap().to_string())
.collect::<Vec<_>>();

expected_symlinks_differences.sort();
expected_folders_differences.sort();
expected_files_differences.sort();

diff_files.sort();
diff_folders.sort();
diff_symlinks.sort();

assert_eq!(diff_files, expected_files_differences);
assert_eq!(diff_folders, expected_folders_differences);
assert_eq!(diff_symlinks, expected_symlinks_differences);
}

fn collect_all_files_and_dirs(dir: &str) -> std::io::Result<CollectedFiles> {
let mut files = BTreeSet::new();
let mut folders = BTreeSet::new();
let mut symlinks = BTreeSet::new();

let mut folders_to_check = vec![dir.to_string()];
while !folders_to_check.is_empty() {
let folder = folders_to_check.pop().unwrap();
let rd = fs::read_dir(folder)?;
for entry in rd {
let entry = entry?;
let path = entry.path();

if path.is_dir() {
folders.insert(path.display().to_string());
folders_to_check.push(path.display().to_string());
} else if path.is_symlink() {
symlinks.insert(path.display().to_string());
} else if path.is_file() {
files.insert(path.display().to_string());
} else {
panic!("Unknown type of file {:?}", path);
}
}
}

folders.remove(dir);
// println!("Found {} files, {} folders and {} symlinks", files.len(), folders.len(), symlinks.len());
Ok(CollectedFiles { files, folders, symlinks })
}
Loading

0 comments on commit 0462324

Please sign in to comment.