aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/e2e/remote_runner.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2021-06-30 11:27:35 +0200
committerGitHub <noreply@github.com>2021-06-30 11:27:35 +0200
commited4fd2a8e77df304539ca7f445a78039028eaa8a (patch)
treeae48b03370b11f3f0987676584724463ac83460d /src/tests/e2e/remote_runner.rs
parentMerge pull request #590 from a-kenji/clippy-fixes (diff)
downloadsl0ppij-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/remote_runner.rs')
-rw-r--r--src/tests/e2e/remote_runner.rs107
1 files changed, 102 insertions, 5 deletions
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;