Fix watch tests for local api and refactor names

pull/195/head
Chip Senkbeil 1 year ago
parent dd91fffeea
commit 718095e99a
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

1
Cargo.lock generated

@ -1975,6 +1975,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d9ba6c734de18ca27c8cef5cd7058aa4ac9f63596131e4c7e41e579319032a2"
dependencies = [
"bitflags 1.3.2",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",

@ -27,8 +27,10 @@ distant-local = "0.20"
## Examples
```rust,no_run
use distant_local::{Config, new_handler};
// Create a server API handler to be used with the server
let handler = distant_local::initialize_handler().unwrap();
let handler = new_handler(Config::default()).unwrap();
```
## License

@ -23,11 +23,11 @@ use state::*;
/// where the server using this api is running. In other words, this is a direct
/// impementation of the API instead of a proxy to another machine as seen with
/// implementations on top of SSH and other protocol.
pub struct LocalDistantApi {
pub struct Api {
state: GlobalState,
}
impl LocalDistantApi {
impl Api {
/// Initialize the api instance
pub fn initialize(config: Config) -> io::Result<Self> {
Ok(Self {
@ -37,7 +37,7 @@ impl LocalDistantApi {
}
#[async_trait]
impl DistantApi for LocalDistantApi {
impl DistantApi for Api {
type LocalData = ();
async fn read_file(
@ -772,8 +772,8 @@ mod tests {
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(100);
async fn setup(buffer: usize) -> (LocalDistantApi, DistantCtx<()>, mpsc::Receiver<Response>) {
let api = LocalDistantApi::initialize(Config {
async fn setup(buffer: usize) -> (Api, DistantCtx<()>, mpsc::Receiver<Response>) {
let api = Api::initialize(Config {
watch: WatchConfig {
debounce_timeout: DEBOUNCE_TIMEOUT,
..Default::default()
@ -1622,7 +1622,7 @@ mod tests {
api.watch(
ctx,
file.path().to_path_buf(),
temp.path().to_path_buf(),
/* recursive */ true,
/* only */ Default::default(),
/* except */ Default::default(),

@ -21,7 +21,7 @@ impl Default for WatchConfig {
native: true,
poll_interval: None,
compare_contents: false,
debounce_timeout: Duration::from_secs(2),
debounce_timeout: Duration::from_millis(500),
debounce_tick_rate: None,
}
}

@ -7,17 +7,14 @@ pub struct ReadmeDoctests;
mod api;
mod config;
mod constants;
pub use api::LocalDistantApi;
pub use api::Api;
pub use config::*;
use distant_core::{DistantApi, DistantApiServerHandler};
/// Implementation of [`DistantApiServerHandler`] using [`LocalDistantApi`].
pub type LocalDistantApiServerHandler =
DistantApiServerHandler<LocalDistantApi, <LocalDistantApi as DistantApi>::LocalData>;
/// Implementation of [`DistantApiServerHandler`] using [`Api`].
pub type Handler = DistantApiServerHandler<Api, <Api as DistantApi>::LocalData>;
/// Initializes a new [`LocalDistantApiServerHandler`].
pub fn initialize_handler(config: Config) -> std::io::Result<LocalDistantApiServerHandler> {
Ok(LocalDistantApiServerHandler::new(
LocalDistantApi::initialize(config)?,
))
/// Initializes a new [`Handler`].
pub fn new_handler(config: Config) -> std::io::Result<Handler> {
Ok(Handler::new(Api::initialize(config)?))
}

@ -6,7 +6,7 @@ use distant_core::net::client::{Client, TcpConnector};
use distant_core::net::common::PortRange;
use distant_core::net::server::Server;
use distant_core::{DistantApiServerHandler, DistantClient};
use distant_local::LocalDistantApi;
use distant_local::Api;
use rstest::*;
use tokio::sync::mpsc;
@ -22,7 +22,7 @@ impl DistantClientCtx {
let (started_tx, mut started_rx) = mpsc::channel::<u16>(1);
tokio::spawn(async move {
if let Ok(api) = LocalDistantApi::initialize(Default::default()) {
if let Ok(api) = Api::initialize(Default::default()) {
let port: PortRange = "0".parse().unwrap();
let port = {
let handler = DistantApiServerHandler::new(api);

@ -140,7 +140,7 @@ async fn async_run(cmd: ServerSubcommand, _is_forked: bool) -> CliResult {
"using an ephemeral port".to_string()
}
);
let handler = distant_local::initialize_handler(Default::default())
let handler = distant_local::new_handler(Default::default())
.context("Failed to create local distant api")?;
let server = Server::tcp()
.config(NetServerConfig {

Loading…
Cancel
Save