mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
add http options
command (#9365)
# Description closes: #9344 Different to other http commands, `http options` command always returns header, according to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS), the response information is included in header. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
mod delete;
|
||||
mod get;
|
||||
mod head;
|
||||
mod options;
|
||||
mod patch;
|
||||
mod post;
|
||||
mod put;
|
||||
|
43
crates/nu-command/tests/commands/network/http/options.rs
Normal file
43
crates/nu-command/tests/commands/network/http/options.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use mockito::Server;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn http_options_is_success() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server
|
||||
.mock("OPTIONS", "/")
|
||||
.with_header("Allow", "OPTIONS, GET")
|
||||
.create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
http options {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(!actual.out.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_options_failed_due_to_server_error() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server.mock("OPTIONS", "/").with_status(400).create();
|
||||
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"
|
||||
http options {url}
|
||||
"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Bad request (400)"))
|
||||
}
|
Reference in New Issue
Block a user