fix testing

This commit is contained in:
Kunal Mohan 2021-05-12 20:45:27 +05:30
parent c5675e965b
commit e203f96d78
19 changed files with 64 additions and 33 deletions

View File

@ -72,6 +72,7 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
std::env::set_var(&"ZELLIJ", "0");
#[cfg(not(test))]
spawn_server(&*ZELLIJ_IPC_PIPE).unwrap();
let mut command_is_executing = CommandIsExecuting::new();

View File

@ -14,10 +14,10 @@ use structopt::StructOpt;
use crate::cli::CliArgs;
use crate::command_is_executing::CommandIsExecuting;
use crate::common::input::{config::Config, options::Options};
use crate::os_input_output::{get_client_os_input, get_server_os_input, ClientOsApi, ServerOsApi};
use crate::common::input::config::Config;
use crate::os_input_output::{get_client_os_input, get_server_os_input};
use crate::utils::{
consts::{ZELLIJ_IPC_PIPE, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
logging::*,
};
use std::convert::TryFrom;
@ -48,14 +48,3 @@ pub fn main() {
}
}
}
pub fn start(
client_os_input: Box<dyn ClientOsApi>,
opts: CliArgs,
server_os_input: Box<dyn ServerOsApi>,
config: Config,
config_options: Options,
) {
start_server(server_os_input, ZELLIJ_IPC_PIPE.clone());
start_client(client_os_input, opts, config);
//drop(ipc_thread.join());
}

View File

@ -1,7 +1,5 @@
pub mod route;
use daemonize::Daemonize;
use interprocess::local_socket::LocalSocketListener;
use std::sync::{Arc, RwLock};
use std::thread;
use std::{path::PathBuf, sync::mpsc};
@ -13,7 +11,7 @@ use crate::common::thread_bus::{Bus, ThreadSenders};
use crate::common::{
errors::ContextType,
ipc::{ClientToServerMsg, ServerToClientMsg},
os_input_output::{set_permissions, ServerOsApi},
os_input_output::ServerOsApi,
pty::{pty_thread_main, Pty, PtyInstruction},
screen::{screen_thread_main, ScreenInstruction},
setup::install::populate_data_dir,
@ -65,7 +63,8 @@ impl Drop for SessionMetaData {
}
pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
Daemonize::new()
#[cfg(not(test))]
daemonize::Daemonize::new()
.working_directory(std::env::var("HOME").unwrap())
.umask(0o077)
.start()
@ -105,6 +104,9 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
let _ = thread::Builder::new()
.name("server_listener".to_string())
.spawn({
use crate::common::os_input_output::set_permissions;
use interprocess::local_socket::LocalSocketListener;
let os_input = os_input.clone();
let sessions = sessions.clone();
let to_server = to_server.clone();
@ -180,6 +182,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
}
}
}
#[cfg(not(test))]
drop(std::fs::remove_file(&socket_path));
}

View File

@ -3,6 +3,7 @@ use ::insta::assert_snapshot;
use crate::common::input::{config::Config, options::Options};
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::commands::{
BRACKETED_PASTE_END, BRACKETED_PASTE_START, PANE_MODE, QUIT, SCROLL_DOWN_IN_SCROLL_MODE,
SCROLL_MODE, SCROLL_PAGE_DOWN_IN_SCROLL_MODE, SCROLL_PAGE_UP_IN_SCROLL_MODE,
@ -10,7 +11,7 @@ use crate::tests::utils::commands::{
SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE,
};
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())

View File

@ -2,8 +2,9 @@ use crate::panes::PositionAndSize;
use ::insta::assert_snapshot;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -4,8 +4,9 @@ use ::std::collections::HashMap;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::possible_tty_inputs::Bytes;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::QUIT;

View File

@ -4,9 +4,10 @@ use std::path::PathBuf;
use crate::common::input::{config::Config, options::Options};
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::commands::QUIT;
use crate::tests::utils::get_output_frame_snapshots;
use crate::{start, CliArgs};
use crate::CliArgs;
fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -2,8 +2,9 @@ use ::insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -1,9 +1,10 @@
use insta::assert_snapshot;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::CliArgs;
use crate::{panes::PositionAndSize, tests::utils::commands::CLOSE_PANE_IN_PANE_MODE};
use crate::{start, CliArgs};
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -3,9 +3,10 @@ use ::insta::assert_snapshot;
use crate::common::input::{config::Config, options::Options};
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::commands::QUIT;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())

View File

@ -2,8 +2,9 @@ use insta::assert_snapshot;
use crate::panes::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
use crate::tests::start;
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::{start, CliArgs};
use crate::CliArgs;
use crate::common::input::{config::Config, options::Options};
use crate::tests::utils::commands::{

View File

@ -3,3 +3,26 @@ pub mod integration;
pub mod possible_tty_inputs;
pub mod tty_inputs;
pub mod utils;
use crate::cli::CliArgs;
use crate::client::start_client;
use crate::common::input::config::Config;
use crate::os_input_output::{ClientOsApi, ServerOsApi};
use crate::server::start_server;
use std::path::PathBuf;
pub fn start(
client_os_input: Box<dyn ClientOsApi>,
opts: CliArgs,
server_os_input: Box<dyn ServerOsApi>,
config: Config,
) {
let server_thread = std::thread::Builder::new()
.name("server_thread".into())
.spawn(move || {
start_server(server_os_input, PathBuf::from(""));
})
.unwrap();
start_client(client_os_input, opts, config);
let _ = server_thread.join();
}