mirror of https://github.com/chipsenkbeil/distant
Fix file-write and file-append not parsing input correctly
parent
da08d2db4f
commit
32150f0956
@ -0,0 +1,143 @@
|
||||
use crate::cli::{
|
||||
fixtures::*,
|
||||
utils::{random_tenant, FAILURE_LINE},
|
||||
};
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::prelude::*;
|
||||
use distant::ExitCode;
|
||||
use distant_core::{
|
||||
data::{Error, ErrorKind},
|
||||
Request, RequestData, Response, ResponseData,
|
||||
};
|
||||
use rstest::*;
|
||||
|
||||
const FILE_CONTENTS: &str = r#"
|
||||
some text
|
||||
on multiple lines
|
||||
that is a file's contents
|
||||
"#;
|
||||
|
||||
const APPENDED_FILE_CONTENTS: &str = r#"
|
||||
even more
|
||||
file contents
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
fn should_report_ok_when_done(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
file.write_str(FILE_CONTENTS).unwrap();
|
||||
|
||||
// distant action file-append {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-append",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
APPENDED_FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
file.write_str(FILE_CONTENTS).unwrap();
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileAppend {
|
||||
path: file.to_path_buf(),
|
||||
data: APPENDED_FILE_CONTENTS.as_bytes().to_vec(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(res.payload[0], ResponseData::Ok),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn yield_an_error_when_fails(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
// distant action file-append {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-append",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
APPENDED_FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.code(ExitCode::Software.to_i32())
|
||||
.stdout("")
|
||||
.stderr(FAILURE_LINE.clone());
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output_for_error(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileAppend {
|
||||
path: file.to_path_buf(),
|
||||
data: APPENDED_FILE_CONTENTS.as_bytes().to_vec(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
res.payload[0],
|
||||
ResponseData::Error(Error {
|
||||
kind: ErrorKind::NotFound,
|
||||
..
|
||||
})
|
||||
),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
use crate::cli::{
|
||||
fixtures::*,
|
||||
utils::{random_tenant, FAILURE_LINE},
|
||||
};
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::prelude::*;
|
||||
use distant::ExitCode;
|
||||
use distant_core::{
|
||||
data::{Error, ErrorKind},
|
||||
Request, RequestData, Response, ResponseData,
|
||||
};
|
||||
use rstest::*;
|
||||
|
||||
const FILE_CONTENTS: &str = r#"
|
||||
some text
|
||||
on multiple lines
|
||||
that is a file's contents
|
||||
"#;
|
||||
|
||||
const APPENDED_FILE_CONTENTS: &str = r#"
|
||||
even more
|
||||
file contents
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
fn should_report_ok_when_done(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
file.write_str(FILE_CONTENTS).unwrap();
|
||||
|
||||
// distant action file-append-text {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-append-text",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
APPENDED_FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
file.write_str(FILE_CONTENTS).unwrap();
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileAppendText {
|
||||
path: file.to_path_buf(),
|
||||
text: APPENDED_FILE_CONTENTS.to_string(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(res.payload[0], ResponseData::Ok),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn yield_an_error_when_fails(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
// distant action file-append-text {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-append-text",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
APPENDED_FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.code(ExitCode::Software.to_i32())
|
||||
.stdout("")
|
||||
.stderr(FAILURE_LINE.clone());
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output_for_error(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileAppendText {
|
||||
path: file.to_path_buf(),
|
||||
text: APPENDED_FILE_CONTENTS.to_string(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
res.payload[0],
|
||||
ResponseData::Error(Error {
|
||||
kind: ErrorKind::NotFound,
|
||||
..
|
||||
})
|
||||
),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
use crate::cli::{
|
||||
fixtures::*,
|
||||
utils::{random_tenant, FAILURE_LINE},
|
||||
};
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::prelude::*;
|
||||
use distant::ExitCode;
|
||||
use distant_core::{
|
||||
data::{Error, ErrorKind},
|
||||
Request, RequestData, Response, ResponseData,
|
||||
};
|
||||
use rstest::*;
|
||||
|
||||
const FILE_CONTENTS: &str = r#"
|
||||
some text
|
||||
on multiple lines
|
||||
that is a file's contents
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
fn should_report_ok_when_done(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
|
||||
// distant action file-write {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&["file-write", file.to_str().unwrap(), "--", FILE_CONTENTS])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(FILE_CONTENTS);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileWrite {
|
||||
path: file.to_path_buf(),
|
||||
data: FILE_CONTENTS.as_bytes().to_vec(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(res.payload[0], ResponseData::Ok),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(FILE_CONTENTS);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn yield_an_error_when_fails(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
// distant action file-write {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&["file-write", file.to_str().unwrap(), "--", FILE_CONTENTS])
|
||||
.assert()
|
||||
.code(ExitCode::Software.to_i32())
|
||||
.stdout("")
|
||||
.stderr(FAILURE_LINE.clone());
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output_for_error(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileWrite {
|
||||
path: file.to_path_buf(),
|
||||
data: FILE_CONTENTS.as_bytes().to_vec(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
res.payload[0],
|
||||
ResponseData::Error(Error {
|
||||
kind: ErrorKind::NotFound,
|
||||
..
|
||||
})
|
||||
),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
use crate::cli::{
|
||||
fixtures::*,
|
||||
utils::{random_tenant, FAILURE_LINE},
|
||||
};
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::prelude::*;
|
||||
use distant::ExitCode;
|
||||
use distant_core::{
|
||||
data::{Error, ErrorKind},
|
||||
Request, RequestData, Response, ResponseData,
|
||||
};
|
||||
use rstest::*;
|
||||
|
||||
const FILE_CONTENTS: &str = r#"
|
||||
some text
|
||||
on multiple lines
|
||||
that is a file's contents
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
fn should_report_ok_when_done(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
|
||||
// distant action file-write-text {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-write-text",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(FILE_CONTENTS);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("test-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileWriteText {
|
||||
path: file.to_path_buf(),
|
||||
text: FILE_CONTENTS.to_string(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(res.payload[0], ResponseData::Ok),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(FILE_CONTENTS);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn yield_an_error_when_fails(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
// distant action file-write {path} -- {contents}
|
||||
action_cmd
|
||||
.args(&[
|
||||
"file-write-text",
|
||||
file.to_str().unwrap(),
|
||||
"--",
|
||||
FILE_CONTENTS,
|
||||
])
|
||||
.assert()
|
||||
.code(ExitCode::Software.to_i32())
|
||||
.stdout("")
|
||||
.stderr(FAILURE_LINE.clone());
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn should_support_json_output_for_error(mut action_cmd: Command) {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let file = temp.child("missing-dir").child("missing-file");
|
||||
|
||||
let req = Request {
|
||||
id: rand::random(),
|
||||
tenant: random_tenant(),
|
||||
payload: vec![RequestData::FileWriteText {
|
||||
path: file.to_path_buf(),
|
||||
text: FILE_CONTENTS.to_string(),
|
||||
}],
|
||||
};
|
||||
|
||||
// distant action --format json --interactive
|
||||
let cmd = action_cmd
|
||||
.args(&["--format", "json"])
|
||||
.arg("--interactive")
|
||||
.write_stdin(format!("{}\n", serde_json::to_string(&req).unwrap()))
|
||||
.assert()
|
||||
.success()
|
||||
.stderr("");
|
||||
|
||||
let res: Response = serde_json::from_slice(&cmd.get_output().stdout).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
res.payload[0],
|
||||
ResponseData::Error(Error {
|
||||
kind: ErrorKind::NotFound,
|
||||
..
|
||||
})
|
||||
),
|
||||
"Unexpected response: {:?}",
|
||||
res.payload[0]
|
||||
);
|
||||
|
||||
// Because we're talking to a local server, we can verify locally
|
||||
file.assert(predicates::path::missing());
|
||||
}
|
@ -1,2 +1,6 @@
|
||||
mod file_append;
|
||||
mod file_append_text;
|
||||
mod file_read;
|
||||
mod file_read_text;
|
||||
mod file_write;
|
||||
mod file_write_text;
|
||||
|
Loading…
Reference in New Issue