fixing tests
This commit is contained in:
parent
92f43bb0ac
commit
ab85088f34
|
@ -163,7 +163,7 @@ fn run_delete(
|
|||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let (data, maybe_metadata) = call
|
||||
.opt::<Value>(engine_state, stack, 1)?
|
||||
.get_flag::<Value>(engine_state, stack, "data")?
|
||||
.map(|v| (HttpBody::Value(v), None))
|
||||
.unwrap_or_else(|| match input {
|
||||
PipelineData::Value(v, metadata) => (HttpBody::Value(v), metadata),
|
||||
|
@ -176,16 +176,6 @@ fn run_delete(
|
|||
.get_flag(engine_state, stack, "content-type")?
|
||||
.or_else(|| maybe_metadata.and_then(|m| m.content_type));
|
||||
|
||||
if let HttpBody::None = data {
|
||||
return Err(ShellError::GenericError {
|
||||
error: "Data must be provided either through pipeline or positional argument".into(),
|
||||
msg: "".into(),
|
||||
span: Some(call.head),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let args = Arguments {
|
||||
url: call.req(engine_state, stack, 0)?,
|
||||
headers: call.get_flag(engine_state, stack, "headers")?,
|
||||
|
|
|
@ -20,6 +20,25 @@ fn http_delete_is_success() {
|
|||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_delete_is_success_pipeline() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server.mock("DELETE", "/").create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
"foo" | http delete {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_delete_failed_due_to_server_error() {
|
||||
let mut server = Server::new();
|
||||
|
|
|
@ -20,6 +20,25 @@ fn http_patch_is_success() {
|
|||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_patch_is_success_pipeline() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server.mock("PATCH", "/").match_body("foo").create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
"foo" | http patch {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_patch_failed_due_to_server_error() {
|
||||
let mut server = Server::new();
|
||||
|
@ -55,7 +74,9 @@ fn http_patch_failed_due_to_missing_body() {
|
|||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Usage: http patch"))
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Data must be provided either through pipeline or positional argument"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -19,6 +19,24 @@ fn http_post_is_success() {
|
|||
|
||||
assert!(actual.out.is_empty())
|
||||
}
|
||||
#[test]
|
||||
fn http_post_is_success_pipeline() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server.mock("POST", "/").match_body("foo").create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
"foo" | http post {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_post_failed_due_to_server_error() {
|
||||
|
@ -55,7 +73,9 @@ fn http_post_failed_due_to_missing_body() {
|
|||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Usage: http post"))
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Data must be provided either through pipeline or positional argument"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -20,6 +20,25 @@ fn http_put_is_success() {
|
|||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_put_is_success_pipeline() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server.mock("PUT", "/").match_body("foo").create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
"foo" | http put {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_put_failed_due_to_server_error() {
|
||||
let mut server = Server::new();
|
||||
|
@ -55,7 +74,9 @@ fn http_put_failed_due_to_missing_body() {
|
|||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Usage: http put"))
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Data must be provided either through pipeline or positional argument"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue
Block a user