-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #57. add -o cli param to write stdout to a file.
- Loading branch information
René Perschon
committed
Apr 7, 2023
1 parent
1225856
commit 084cca5
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use anyhow::Result; | ||
use assert_cmd::Command; | ||
use fhttp_test_utils::write_test_file; | ||
use mockito::mock; | ||
use rstest::rstest; | ||
use temp_dir::TempDir; | ||
|
||
#[rstest] | ||
async fn should_output_to_new_file() -> Result<()> { | ||
let workdir = TempDir::new()?; | ||
|
||
let req = write_test_file(&workdir, "req.http", "GET ${env(URL)}/foo")?; | ||
let out = workdir.path().join("output.txt"); | ||
|
||
let request = mock("GET", "/foo") | ||
.with_body("OK") | ||
.create(); | ||
|
||
Command::cargo_bin("fhttp") | ||
.unwrap() | ||
.env("URL", &mockito::server_url()) | ||
.arg("-o") | ||
.arg(out.to_str().unwrap()) | ||
.arg(req.to_str()) | ||
.assert() | ||
.success(); | ||
|
||
let result = std::fs::read_to_string(out)?; | ||
assert_eq!(&result, "OK\n"); | ||
request.assert(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[rstest] | ||
async fn should_output_to_and_overwrite_existing_file() -> Result<()> { | ||
let workdir = TempDir::new()?; | ||
|
||
let req = write_test_file(&workdir, "req.http", "GET ${env(URL)}/foo")?; | ||
let out = workdir.path().join("output.txt"); | ||
std::fs::write(&out, "original content")?; | ||
|
||
let request = mock("GET", "/foo") | ||
.with_body("OK") | ||
.create(); | ||
|
||
Command::cargo_bin("fhttp") | ||
.unwrap() | ||
.env("URL", &mockito::server_url()) | ||
.arg("-o") | ||
.arg(out.to_str().unwrap()) | ||
.arg(req.to_str()) | ||
.assert() | ||
.success(); | ||
|
||
let result = std::fs::read_to_string(&out)?; | ||
assert_eq!(&result, "OK\n"); | ||
request.assert(); | ||
|
||
Ok(()) | ||
} |