nushell/crates/nu-command/tests/commands/network/http/options.rs
WindSoilder 1edd3e7c3b
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.
-->
2023-06-09 08:00:40 -05:00

44 lines
855 B
Rust

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)"))
}