test tweaks

pull/146/head
Chip Senkbeil 2 years ago
parent 8abb180b4a
commit 400025855f
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -2,6 +2,7 @@ use assert_cmd::Command;
use derive_more::{Deref, DerefMut};
use once_cell::sync::Lazy;
use rstest::*;
use serde_json::json;
use std::{
io,
path::PathBuf,
@ -273,5 +274,25 @@ pub fn json_repl(ctx: DistantManagerCtx) -> CtxCommand<Repl> {
.spawn()
.expect("Failed to start distant repl with json format");
let cmd = Repl::new(child, TIMEOUT);
CtxCommand { ctx, cmd }
}
pub async fn validate_authentication(repl: &mut Repl) {
// NOTE: We have to handle receiving authentication messages, as we will get
// an authentication initialization of with method "none", and then
// a finish authentication status before we can do anything else.
let json = repl
.read_json_from_stdout()
.await
.unwrap()
.expect("Missing authentication initialization");
assert_eq!(json, json!({"type": "initialization", "methods": ["none"]}));
let json = repl
.write_and_read_json(json!({"type": "initialization", "methods": ["none"]}))
.await
.unwrap()
.expect("Missing authentication finalization");
assert_eq!(json, json!({"type": "finished"}));
}

@ -6,6 +6,8 @@ const EXPECTED_TABLE: &str = indoc! {"
+---------------+--------------------------------------------------------------+
| kind | description |
+---------------+--------------------------------------------------------------+
| authenticate | Supports authenticating with a remote server |
+---------------+--------------------------------------------------------------+
| capabilities | Supports retrieving capabilities |
+---------------+--------------------------------------------------------------+
| channel | Supports sending data through a channel with a remote server |
@ -18,14 +20,12 @@ const EXPECTED_TABLE: &str = indoc! {"
+---------------+--------------------------------------------------------------+
| kill | Supports killing a remote connection |
+---------------+--------------------------------------------------------------+
| launch | Supports launching distant on remote servers |
| launch | Supports launching a server on remote machines |
+---------------+--------------------------------------------------------------+
| list | Supports retrieving a list of managed connections |
+---------------+--------------------------------------------------------------+
| open_channel | Supports opening a channel with a remote server |
+---------------+--------------------------------------------------------------+
| shutdown | Supports being shut down on demand |
+---------------+--------------------------------------------------------------+
"};
#[rstest]

@ -6,6 +6,8 @@ use serde_json::json;
#[rstest]
#[tokio::test]
async fn should_support_json_capabilities(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let id = rand::random::<u64>().to_string();
let req = json!({
"id": id,

@ -13,6 +13,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_copying_file(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let src = temp.child("file");
@ -48,6 +50,8 @@ async fn should_support_json_copying_file(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_copying_nonempty_directory(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Make a non-empty directory
@ -87,6 +91,8 @@ async fn should_support_json_copying_nonempty_directory(mut json_repl: CtxComman
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let src = temp.child("dir");

@ -7,6 +7,8 @@ use serde_json::json;
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let dir = temp.child("dir");
@ -40,6 +42,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
async fn should_support_json_creating_missing_parent_directories_if_specified(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let dir = temp.child("dir1").child("dir2");
@ -71,6 +75,8 @@ async fn should_support_json_creating_missing_parent_directories_if_specified(
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let dir = temp.child("missing-dir").child("dir");

@ -71,6 +71,8 @@ fn make_directory() -> assert_fs::TempDir {
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = make_directory();
let id = rand::random::<u64>().to_string();
@ -110,6 +112,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
async fn should_support_json_returning_absolute_paths_if_specified(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = make_directory();
// NOTE: Our root path is always canonicalized, so the absolute path
@ -153,6 +157,8 @@ async fn should_support_json_returning_absolute_paths_if_specified(
async fn should_support_json_returning_all_files_and_directories_if_depth_is_0(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = make_directory();
let id = rand::random::<u64>().to_string();
@ -202,6 +208,8 @@ async fn should_support_json_returning_all_files_and_directories_if_depth_is_0(
async fn should_support_json_including_root_directory_if_specified(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = make_directory();
// NOTE: Our root path is always canonicalized, so yielded entry
@ -244,6 +252,8 @@ async fn should_support_json_including_root_directory_if_specified(
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = make_directory();
let dir = temp.child("missing-dir");

@ -6,6 +6,8 @@ use serde_json::json;
#[rstest]
#[tokio::test]
async fn should_support_json_true_if_exists(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Create file
@ -37,6 +39,8 @@ async fn should_support_json_true_if_exists(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_false_if_not_exists(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Don't create file

@ -17,6 +17,8 @@ file contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
file.write_str(FILE_CONTENTS).unwrap();
@ -52,6 +54,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-dir").child("missing-file");

@ -17,6 +17,8 @@ file contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
file.write_str(FILE_CONTENTS).unwrap();
@ -52,6 +54,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-dir").child("missing-file");

@ -12,6 +12,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
file.write_str(FILE_CONTENTS).unwrap();
@ -41,6 +43,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-file");

@ -12,6 +12,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
file.write_str(FILE_CONTENTS).unwrap();
@ -41,6 +43,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-file");

@ -12,6 +12,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
@ -46,6 +48,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-dir").child("missing-file");

@ -12,6 +12,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("test-file");
@ -46,6 +48,8 @@ async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("missing-dir").child("missing-file");

@ -12,6 +12,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_metadata_for_file(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("file");
@ -44,6 +46,8 @@ async fn should_support_json_metadata_for_file(mut json_repl: CtxCommand<Repl>)
#[rstest]
#[tokio::test]
async fn should_support_json_metadata_for_directory(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let dir = temp.child("dir");
@ -78,6 +82,8 @@ async fn should_support_json_metadata_for_directory(mut json_repl: CtxCommand<Re
async fn should_support_json_metadata_for_including_a_canonicalized_path(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("file");
@ -115,6 +121,8 @@ async fn should_support_json_metadata_for_including_a_canonicalized_path(
async fn should_support_json_metadata_for_resolving_file_type_of_symlink(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("file");
@ -144,6 +152,8 @@ async fn should_support_json_metadata_for_resolving_file_type_of_symlink(
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Don't create file

@ -73,6 +73,8 @@ fn check_value_as_str(value: &serde_json::Value, other: &str) {
async fn should_support_json_to_execute_program_and_return_exit_status(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let cmd = make_cmd(vec![ECHO_ARGS_TO_STDOUT.to_str().unwrap()]);
let id = rand::random::<u64>().to_string();
@ -95,6 +97,8 @@ async fn should_support_json_to_execute_program_and_return_exit_status(
#[rstest]
#[tokio::test]
async fn should_support_json_to_capture_and_print_stdout(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let cmd = make_cmd(vec![ECHO_ARGS_TO_STDOUT.to_str().unwrap(), "some output"]);
// Spawn the process
@ -132,6 +136,8 @@ async fn should_support_json_to_capture_and_print_stdout(mut json_repl: CtxComma
#[rstest]
#[tokio::test]
async fn should_support_json_to_capture_and_print_stderr(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let cmd = make_cmd(vec![ECHO_ARGS_TO_STDERR.to_str().unwrap(), "some output"]);
// Spawn the process
@ -169,6 +175,8 @@ async fn should_support_json_to_capture_and_print_stderr(mut json_repl: CtxComma
#[rstest]
#[tokio::test]
async fn should_support_json_to_forward_stdin_to_remote_process(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let cmd = make_cmd(vec![ECHO_STDIN_TO_STDOUT.to_str().unwrap()]);
// Spawn the process
@ -254,6 +262,8 @@ async fn should_support_json_to_forward_stdin_to_remote_process(mut json_repl: C
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let id = rand::random::<u64>().to_string();
let req = json!({
"id": id,

@ -7,6 +7,8 @@ use serde_json::json;
#[rstest]
#[tokio::test]
async fn should_support_json_removing_file(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("file");
@ -39,6 +41,8 @@ async fn should_support_json_removing_file(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_removing_empty_directory(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Make an empty directory
@ -74,6 +78,8 @@ async fn should_support_json_removing_empty_directory(mut json_repl: CtxCommand<
async fn should_support_json_removing_nonempty_directory_if_force_specified(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Make an empty directory
@ -107,6 +113,8 @@ async fn should_support_json_removing_nonempty_directory_if_force_specified(
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Make a non-empty directory so we fail to remove it

@ -13,6 +13,8 @@ that is a file's contents
#[rstest]
#[tokio::test]
async fn should_support_json_renaming_file(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let src = temp.child("file");
@ -48,6 +50,8 @@ async fn should_support_json_renaming_file(mut json_repl: CtxCommand<Repl>) {
#[rstest]
#[tokio::test]
async fn should_support_json_renaming_nonempty_directory(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
// Make a non-empty directory
@ -90,6 +94,8 @@ async fn should_support_json_renaming_nonempty_directory(mut json_repl: CtxComma
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let src = temp.child("dir");

@ -6,6 +6,8 @@ use serde_json::json;
#[rstest]
#[tokio::test]
async fn should_support_json_search_filesystem_using_query(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let root = assert_fs::TempDir::new().unwrap();
root.child("file1.txt").write_str("some file text").unwrap();
root.child("file2.txt")

@ -6,6 +6,8 @@ use std::env;
#[rstest]
#[tokio::test]
async fn should_support_json_system_info(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let id = rand::random::<u64>().to_string();
let req = json!({
"id": id,

@ -19,6 +19,8 @@ async fn wait_millis(millis: u64) {
#[rstest]
#[tokio::test]
async fn should_support_json_watching_single_file(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file = temp.child("file");
@ -67,6 +69,8 @@ async fn should_support_json_watching_single_file(mut json_repl: CtxCommand<Repl
#[rstest]
#[tokio::test]
async fn should_support_json_watching_directory_recursively(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let dir = temp.child("dir");
@ -139,6 +143,8 @@ async fn should_support_json_watching_directory_recursively(mut json_repl: CtxCo
async fn should_support_json_reporting_changes_using_correct_request_id(
mut json_repl: CtxCommand<Repl>,
) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let file1 = temp.child("file1");
@ -243,6 +249,8 @@ async fn should_support_json_reporting_changes_using_correct_request_id(
#[rstest]
#[tokio::test]
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
validate_authentication(&mut json_repl).await;
let temp = assert_fs::TempDir::new().unwrap();
let path = temp.to_path_buf().join("missing");

Loading…
Cancel
Save