diff options
| author | Aram Drevekenin <aram@poor.dev> | 2021-06-30 11:27:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-30 11:27:35 +0200 |
| commit | ed4fd2a8e77df304539ca7f445a78039028eaa8a (patch) | |
| tree | ae48b03370b11f3f0987676584724463ac83460d /src/tests/e2e | |
| parent | Merge pull request #590 from a-kenji/clippy-fixes (diff) | |
| download | sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.tar.gz sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.tar.xz sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.zip | |
chore(tests): move all integration tests to be either unit or e2e tests - remove old testing infra (#589)
* tests(integration): move basic integration tests to be unit tests
* fix(tests): silently fail threadbus for tests
* tests(unit): move compatibility tests to become unit tests for grid
* tests(unit): move close_pane tests to become unit tests for grid
* tests(e2e): move basic layout test to e2e
* tests(unit): move move_focus tests to be unit tests
* tests(unit): move resize_down tests to be unit tests
* tests(unit): move resize_left tests to be unit tests
* tests(unit): move resize_right tests to be unit tests
* tests(unit): move resize_up tests to be unit tests
* tests(infra): remove unused infra
* style(fmt): make rustfmt happy
* debug
* debug
* debug
* debug
* chore(test): shift volume mounting around because github actions is a special child
Diffstat (limited to 'src/tests/e2e')
| -rw-r--r-- | src/tests/e2e/cases.rs | 83 | ||||
| -rw-r--r-- | src/tests/e2e/remote_runner.rs | 107 | ||||
| -rw-r--r-- | src/tests/e2e/snapshots/zellij__tests__e2e__cases__accepts_basic_layout.snap | 29 |
3 files changed, 208 insertions, 11 deletions
diff --git a/src/tests/e2e/cases.rs b/src/tests/e2e/cases.rs index 5af67074..69233f25 100644 --- a/src/tests/e2e/cases.rs +++ b/src/tests/e2e/cases.rs @@ -1,15 +1,58 @@ +#![allow(unused)] + use ::insta::assert_snapshot; use zellij_utils::pane_size::PositionAndSize; use rand::Rng; +use std::path::Path; + use super::remote_runner::{RemoteRunner, RemoteTerminal, Step}; -use crate::tests::utils::commands::{ - CLOSE_PANE_IN_PANE_MODE, DETACH_IN_SESSION_MODE, ENTER, LOCK_MODE, NEW_TAB_IN_TAB_MODE, - PANE_MODE, QUIT, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, SCROLL_MODE, - SCROLL_UP_IN_SCROLL_MODE, SESSION_MODE, SPLIT_RIGHT_IN_PANE_MODE, TAB_MODE, - TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, -}; + +pub const QUIT: [u8; 1] = [17]; // ctrl-q +pub const ESC: [u8; 1] = [27]; +pub const ENTER: [u8; 1] = [10]; // char '\n' +pub const LOCK_MODE: [u8; 1] = [7]; // ctrl-g + +pub const MOVE_FOCUS_LEFT_IN_NORMAL_MODE: [u8; 2] = [27, 104]; // alt-h +pub const MOVE_FOCUS_RIGHT_IN_NORMAL_MODE: [u8; 2] = [27, 108]; // alt-l + +pub const PANE_MODE: [u8; 1] = [16]; // ctrl-p +pub const SPAWN_TERMINAL_IN_PANE_MODE: [u8; 1] = [110]; // n +pub const MOVE_FOCUS_IN_PANE_MODE: [u8; 1] = [112]; // p +pub const SPLIT_DOWN_IN_PANE_MODE: [u8; 1] = [100]; // d +pub const SPLIT_RIGHT_IN_PANE_MODE: [u8; 1] = [114]; // r +pub const TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE: [u8; 1] = [102]; // f +pub const CLOSE_PANE_IN_PANE_MODE: [u8; 1] = [120]; // x +pub const MOVE_FOCUS_DOWN_IN_PANE_MODE: [u8; 1] = [106]; // j +pub const MOVE_FOCUS_UP_IN_PANE_MODE: [u8; 1] = [107]; // k +pub const MOVE_FOCUS_LEFT_IN_PANE_MODE: [u8; 1] = [104]; // h +pub const MOVE_FOCUS_RIGHT_IN_PANE_MODE: [u8; 1] = [108]; // l + +pub const SCROLL_MODE: [u8; 1] = [19]; // ctrl-s +pub const SCROLL_UP_IN_SCROLL_MODE: [u8; 1] = [107]; // k +pub const SCROLL_DOWN_IN_SCROLL_MODE: [u8; 1] = [106]; // j +pub const SCROLL_PAGE_UP_IN_SCROLL_MODE: [u8; 1] = [2]; // ctrl-b +pub const SCROLL_PAGE_DOWN_IN_SCROLL_MODE: [u8; 1] = [6]; // ctrl-f + +pub const RESIZE_MODE: [u8; 1] = [18]; // ctrl-r +pub const RESIZE_DOWN_IN_RESIZE_MODE: [u8; 1] = [106]; // j +pub const RESIZE_UP_IN_RESIZE_MODE: [u8; 1] = [107]; // k +pub const RESIZE_LEFT_IN_RESIZE_MODE: [u8; 1] = [104]; // h +pub const RESIZE_RIGHT_IN_RESIZE_MODE: [u8; 1] = [108]; // l + +pub const TAB_MODE: [u8; 1] = [20]; // ctrl-t +pub const NEW_TAB_IN_TAB_MODE: [u8; 1] = [110]; // n +pub const SWITCH_NEXT_TAB_IN_TAB_MODE: [u8; 1] = [108]; // l +pub const SWITCH_PREV_TAB_IN_TAB_MODE: [u8; 1] = [104]; // h +pub const CLOSE_TAB_IN_TAB_MODE: [u8; 1] = [120]; // x + +pub const SESSION_MODE: [u8; 1] = [15]; // ctrl-o +pub const DETACH_IN_SESSION_MODE: [u8; 1] = [100]; // d + +pub const BRACKETED_PASTE_START: [u8; 6] = [27, 91, 50, 48, 48, 126]; // \u{1b}[200~ +pub const BRACKETED_PASTE_END: [u8; 6] = [27, 91, 50, 48, 49, 126]; // \u{1b}[201 +pub const SLEEP: [u8; 0] = []; // All the E2E tests are marked as "ignored" so that they can be run separately from the normal // tests @@ -714,3 +757,31 @@ pub fn detach_and_attach_session() { .run_all_steps(); assert_snapshot!(last_snapshot); } + +#[test] +#[ignore] +pub fn accepts_basic_layout() { + let fake_win_size = PositionAndSize { + cols: 120, + rows: 24, + x: 0, + y: 0, + ..Default::default() + }; + let layout_file_name = "three-panes-with-nesting.yaml"; + let last_snapshot = RemoteRunner::new_with_layout("accepts_basic_layout", fake_win_size, layout_file_name, None) + .add_step(Step { + name: "Wait for app to load", + instruction: |remote_terminal: RemoteTerminal| -> bool { + let mut step_is_complete = false; + if remote_terminal.cursor_position_is(2, 0) + && remote_terminal.snapshot_contains("$ █ │$") + && remote_terminal.snapshot_contains("$ ") { + step_is_complete = true; + } + step_is_complete + }, + }) + .run_all_steps(); + assert_snapshot!(last_snapshot); +} diff --git a/src/tests/e2e/remote_runner.rs b/src/tests/e2e/remote_runner.rs index b53c3129..053df477 100644 --- a/src/tests/e2e/remote_runner.rs +++ b/src/tests/e2e/remote_runner.rs @@ -8,7 +8,10 @@ use ssh2::Session; use std::io::prelude::*; use std::net::TcpStream; +use std::path::Path; + const ZELLIJ_EXECUTABLE_LOCATION: &str = "/usr/src/zellij/x86_64-unknown-linux-musl/debug/zellij"; +const ZELLIJ_LAYOUT_PATH: &str = "/usr/src/zellij/fixtures/layouts"; const CONNECTION_STRING: &str = "127.0.0.1:2222"; const CONNECTION_USERNAME: &str = "test"; const CONNECTION_PASSWORD: &str = "test"; @@ -54,6 +57,38 @@ fn start_zellij(channel: &mut ssh2::Channel, session_name: Option<&String>) { channel.flush().unwrap(); } +fn start_zellij_with_layout( + channel: &mut ssh2::Channel, + layout_path: &str, + session_name: Option<&String>, +) { + match session_name.as_ref() { + Some(name) => { + channel + .write_all( + format!( + "{} --layout-path {} --session {}\n", + ZELLIJ_EXECUTABLE_LOCATION, layout_path, name + ) + .as_bytes(), + ) + .unwrap(); + } + None => { + channel + .write_all( + format!( + "{} --layout-path {}\n", + ZELLIJ_EXECUTABLE_LOCATION, layout_path + ) + .as_bytes(), + ) + .unwrap(); + } + }; + channel.flush().unwrap(); +} + pub fn take_snapshot(terminal_output: &mut TerminalPane) -> String { let output_lines = terminal_output.read_buffer_as_lines(); let cursor_coordinates = terminal_output.cursor_coordinates(); @@ -107,6 +142,20 @@ impl<'a> RemoteTerminal<'a> { pub fn snapshot_contains(&self, text: &str) -> bool { self.current_snapshot.contains(text) } + #[allow(unused)] + pub fn current_snapshot(&self) -> String { + // convenience method for writing tests, + // this should only be used when developing, + // please prefer "snapsht_contains" instead + self.current_snapshot.clone() + } + #[allow(unused)] + pub fn current_cursor_position(&self) -> String { + // convenience method for writing tests, + // this should only be used when developing, + // please prefer "cursor_position_is" instead + format!("x: {}, y: {}", self.cursor_x, self.cursor_y) + } pub fn send_key(&mut self, key: &[u8]) { self.channel.write(key).unwrap(); self.channel.flush().unwrap(); @@ -148,6 +197,7 @@ pub struct RemoteRunner { currently_running_step: Option<String>, retries_left: usize, win_size: PositionAndSize, + layout_file_name: Option<&'static str>, } impl RemoteRunner { @@ -173,6 +223,39 @@ impl RemoteRunner { current_step_index: 0, retries_left: 3, win_size, + layout_file_name: None, + } + } + pub fn new_with_layout( + test_name: &'static str, + win_size: PositionAndSize, + layout_file_name: &'static str, + session_name: Option<String>, + ) -> Self { + // let layout_file_name = local_layout_path.file_name().unwrap(); + let remote_path = Path::new(ZELLIJ_LAYOUT_PATH).join(layout_file_name); // TODO: not hardcoded + let sess = ssh_connect(); + let mut channel = sess.channel_session().unwrap(); + let vte_parser = vte::Parser::new(); + let terminal_output = TerminalPane::new(0, win_size, Palette::default()); + setup_remote_environment(&mut channel, win_size); + start_zellij_with_layout( + &mut channel, + &remote_path.to_string_lossy(), + session_name.as_ref(), + ); + RemoteRunner { + steps: vec![], + channel, + terminal_output, + vte_parser, + session_name, + test_name, + currently_running_step: None, + current_step_index: 0, + retries_left: 3, + win_size, + layout_file_name: Some(layout_file_name), } } pub fn add_step(mut self, step: Step) -> Self { @@ -220,11 +303,25 @@ impl RemoteRunner { // inside the container format!("{}_{}", name, self.retries_left) }); - let mut new_runner = RemoteRunner::new(self.test_name, self.win_size, session_name); - new_runner.retries_left = self.retries_left - 1; - new_runner.replace_steps(self.steps.clone()); - drop(std::mem::replace(self, new_runner)); - self.run_all_steps() + if let Some(layout_file_name) = self.layout_file_name.as_ref() { + // let mut new_runner = RemoteRunner::new_with_layout(self.test_name, self.win_size, Path::new(&local_layout_path), session_name); + let mut new_runner = RemoteRunner::new_with_layout( + self.test_name, + self.win_size, + layout_file_name, + session_name, + ); + new_runner.retries_left = self.retries_left - 1; + new_runner.replace_steps(self.steps.clone()); + drop(std::mem::replace(self, new_runner)); + self.run_all_steps() + } else { + let mut new_runner = RemoteRunner::new(self.test_name, self.win_size, session_name); + new_runner.retries_left = self.retries_left - 1; + new_runner.replace_steps(self.steps.clone()); + drop(std::mem::replace(self, new_runner)); + self.run_all_steps() + } } fn display_informative_error(&mut self) { let test_name = self.test_name; diff --git a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__accepts_basic_layout.snap b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__accepts_basic_layout.snap new file mode 100644 index 00000000..5556153a --- /dev/null +++ b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__accepts_basic_layout.snap @@ -0,0 +1,29 @@ +--- +source: src/tests/e2e/cases.rs +expression: last_snapshot + +--- +$ █ │$ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ + │ +───────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────── +$ + + + + |
