coliru

A minimal, flexible, dotfile installer
git clone https://git.ashermorgan.net/coliru/
Log | Files | Refs | README

commit 1a96fc9c592f6fb9e767d4f30f32fba6add4f5e7
parent 71565884e30ad6832005d0edf2a83babb276abd9
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat,  6 Jul 2024 15:30:04 -0700

Improve how test ssh arguments are injected

Diffstat:
Msrc/ssh.rs | 8++++----
Mtests/test_utils/mod.rs | 6+++++-
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/ssh.rs b/src/ssh.rs @@ -12,6 +12,7 @@ //! ``` use anyhow::{bail, anyhow, Context, Result}; +use std::env; use shellexpand::tilde_with_context; use std::fs::{read_dir, remove_dir_all}; use std::path::{MAIN_SEPARATOR_STR, Path, PathBuf}; @@ -140,8 +141,8 @@ fn send_dir(src: &str, dst: &str, host: &str) -> Result<()> { })?.path(); let mut cmd = Command::new("scp"); - if host == "test@localhost" { - // SSH options and port for test server hard coded for now + + if env::var("COLIRU_TEST").is_ok() { cmd.args(["-o", "StrictHostKeyChecking=no", "-P", "2222"]); } cmd.args(["-r", &_src.to_string_lossy(), &format!("{host}:{dst}")]); @@ -165,8 +166,7 @@ fn send_dir(src: &str, dst: &str, host: &str) -> Result<()> { /// ``` pub fn send_command(command: &str, host: &str) -> Result<()> { let mut cmd = Command::new("ssh"); - if host == "test@localhost" { - // SSH options and port for test server hard coded for now + if env::var("COLIRU_TEST").is_ok() { cmd.args(["-o", "StrictHostKeyChecking=no", "-p", "2222"]); } cmd.args([host, command]); diff --git a/tests/test_utils/mod.rs b/tests/test_utils/mod.rs @@ -15,7 +15,9 @@ use std::path::{Path, PathBuf}; use std::process::Command; /// The SSH test server -pub const SSH_HOST: &str = "test@localhost"; // TODO: add explicit port +// StrictHostKeyChecking option and correct port are set automatically in +// src/ssh.rs when COLIRU_TEST environment variable is set. +pub const SSH_HOST: &str = "test@localhost"; /// A set of temporary directories that are automatically deleted when the value /// is dropped @@ -86,6 +88,7 @@ pub fn setup_integration(name: &str) -> TempDirs { if cfg!(target_family = "unix") { env::set_var("HOME", dirs.home.parent().unwrap()); } + env::set_var("COLIRU_TEST", "1"); dirs } @@ -108,6 +111,7 @@ fn setup_e2e(name: &str) -> (TempDirs, Command) { if cfg!(target_family = "unix") { cmd.env("HOME", &dirs.home); } + cmd.env("COLIRU_TEST", "1"); (dirs, cmd) }