2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2021-01-19 07:15:53 +00:00
|
|
|
use std::fs;
|
|
|
|
use tempfile::tempdir;
|
2020-11-29 15:32:21 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2020-11-11 21:33:35 +00:00
|
|
|
#[test]
|
|
|
|
fn test_sync_default() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().succeeds();
|
2020-11-11 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sync_incorrect_arg() {
|
|
|
|
new_ucmd!().arg("--foo").fails();
|
|
|
|
}
|
2020-11-29 15:32:21 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sync_fs() {
|
|
|
|
let temporary_directory = tempdir().unwrap();
|
|
|
|
let temporary_path = fs::canonicalize(temporary_directory.path()).unwrap();
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("--file-system")
|
|
|
|
.arg(&temporary_path)
|
|
|
|
.succeeds();
|
2020-11-29 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sync_data() {
|
|
|
|
// Todo add a second arg
|
|
|
|
let temporary_directory = tempdir().unwrap();
|
|
|
|
let temporary_path = fs::canonicalize(temporary_directory.path()).unwrap();
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().arg("--data").arg(&temporary_path).succeeds();
|
2020-11-29 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sync_no_existing_files() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("--data")
|
|
|
|
.arg("do-no-exist")
|
|
|
|
.fails()
|
2021-05-26 00:07:49 +00:00
|
|
|
.stderr_contains("cannot stat");
|
2020-11-29 15:32:21 +00:00
|
|
|
}
|
2022-09-24 10:46:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sync_data_but_not_file() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--data")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("sync: --data needs at least one argument");
|
|
|
|
}
|
2022-09-24 12:54:19 +00:00
|
|
|
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
#[test]
|
|
|
|
fn test_sync_no_permission_dir() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
let dir = "foo";
|
|
|
|
at.mkdir_all(dir);
|
|
|
|
|
|
|
|
ts.ccmd("chmod").arg("0").arg(dir).succeeds();
|
|
|
|
let result = ts.ucmd().arg("--data").arg(dir).fails();
|
2022-11-04 10:35:54 +00:00
|
|
|
result.stderr_contains("sync: cannot stat 'foo': Permission denied");
|
2022-09-24 12:54:19 +00:00
|
|
|
let result = ts.ucmd().arg(dir).fails();
|
2022-11-04 10:35:54 +00:00
|
|
|
result.stderr_contains("sync: cannot stat 'foo': Permission denied");
|
2022-09-24 12:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
#[test]
|
|
|
|
fn test_sync_no_permission_file() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
let f = "file";
|
|
|
|
at.touch(f);
|
|
|
|
|
|
|
|
ts.ccmd("chmod").arg("0200").arg(f).succeeds();
|
|
|
|
ts.ucmd().arg(f).succeeds();
|
|
|
|
}
|