mirror of https://github.com/chipsenkbeil/distant
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
4.7 KiB
Rust
146 lines
4.7 KiB
Rust
use crate::common::{fixtures::*, lua, poll, session};
|
|
use assert_fs::prelude::*;
|
|
use mlua::chunk;
|
|
use predicates::prelude::*;
|
|
use rstest::*;
|
|
|
|
#[rstest]
|
|
fn should_return_error_on_failure(ctx: &'_ DistantServerCtx) {
|
|
let lua = lua::make().unwrap();
|
|
let new_session = session::make_function(&lua, ctx).unwrap();
|
|
let schedule_fn = poll::make_function(&lua).unwrap();
|
|
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let file = temp.child("missing-file");
|
|
let file_path = file.path().to_str().unwrap();
|
|
|
|
let result = lua
|
|
.load(chunk! {
|
|
local session = $new_session()
|
|
local f = require("distant_lua").utils.wrap_async(
|
|
session.remove_async,
|
|
$schedule_fn
|
|
)
|
|
|
|
// Because of our scheduler, the invocation turns async -> sync
|
|
local err
|
|
f(session, { path = $file_path }, function(success, res)
|
|
if not success then
|
|
err = res
|
|
end
|
|
end)
|
|
assert(err, "Unexpectedly succeeded")
|
|
})
|
|
.exec();
|
|
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
|
|
|
|
// Also, verify that path does not exist
|
|
file.assert(predicate::path::missing());
|
|
}
|
|
|
|
#[rstest]
|
|
fn should_support_deleting_a_directory(ctx: &'_ DistantServerCtx) {
|
|
let lua = lua::make().unwrap();
|
|
let new_session = session::make_function(&lua, ctx).unwrap();
|
|
let schedule_fn = poll::make_function(&lua).unwrap();
|
|
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let dir = temp.child("dir");
|
|
dir.create_dir_all().unwrap();
|
|
let dir_path = dir.path().to_str().unwrap();
|
|
|
|
let result = lua
|
|
.load(chunk! {
|
|
local session = $new_session()
|
|
local f = require("distant_lua").utils.wrap_async(
|
|
session.remove_async,
|
|
$schedule_fn
|
|
)
|
|
|
|
// Because of our scheduler, the invocation turns async -> sync
|
|
local err
|
|
f(session, { path = $dir_path }, function(success, res)
|
|
if not success then
|
|
err = res
|
|
end
|
|
end)
|
|
assert(not err, "Unexpectedly failed")
|
|
})
|
|
.exec();
|
|
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
|
|
|
|
// Also, verify that path does not exist
|
|
dir.assert(predicate::path::missing());
|
|
}
|
|
|
|
#[rstest]
|
|
fn should_delete_nonempty_directory_if_force_is_true(ctx: &'_ DistantServerCtx) {
|
|
let lua = lua::make().unwrap();
|
|
let new_session = session::make_function(&lua, ctx).unwrap();
|
|
let schedule_fn = poll::make_function(&lua).unwrap();
|
|
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let dir = temp.child("dir");
|
|
dir.create_dir_all().unwrap();
|
|
dir.child("file").touch().unwrap();
|
|
let dir_path = dir.path().to_str().unwrap();
|
|
|
|
let result = lua
|
|
.load(chunk! {
|
|
local session = $new_session()
|
|
local f = require("distant_lua").utils.wrap_async(
|
|
session.remove_async,
|
|
$schedule_fn
|
|
)
|
|
|
|
// Because of our scheduler, the invocation turns async -> sync
|
|
local err
|
|
f(session, { path = $dir_path, force = true }, function(success, res)
|
|
if not success then
|
|
err = res
|
|
end
|
|
end)
|
|
assert(not err, "Unexpectedly failed")
|
|
})
|
|
.exec();
|
|
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
|
|
|
|
// Also, verify that path does not exist
|
|
dir.assert(predicate::path::missing());
|
|
}
|
|
|
|
#[rstest]
|
|
fn should_support_deleting_a_single_file(ctx: &'_ DistantServerCtx) {
|
|
let lua = lua::make().unwrap();
|
|
let new_session = session::make_function(&lua, ctx).unwrap();
|
|
let schedule_fn = poll::make_function(&lua).unwrap();
|
|
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let file = temp.child("some-file");
|
|
file.touch().unwrap();
|
|
let file_path = file.path().to_str().unwrap();
|
|
|
|
let result = lua
|
|
.load(chunk! {
|
|
local session = $new_session()
|
|
local f = require("distant_lua").utils.wrap_async(
|
|
session.remove_async,
|
|
$schedule_fn
|
|
)
|
|
|
|
// Because of our scheduler, the invocation turns async -> sync
|
|
local err
|
|
f(session, { path = $file_path }, function(success, res)
|
|
if not success then
|
|
err = res
|
|
end
|
|
end)
|
|
assert(not err, "Unexpectedly failed")
|
|
})
|
|
.exec();
|
|
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
|
|
|
|
// Also, verify that path does not exist
|
|
file.assert(predicate::path::missing());
|
|
}
|