Fix regression in --output when output file doesn't exist.

This commit is contained in:
Jean-Christophe Amiel 2024-08-29 15:07:46 +02:00
parent 16b1e6b72d
commit 062e2ab0f8
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
9 changed files with 38 additions and 8 deletions

View File

@ -1,3 +1,6 @@
[5.0.1 (TO_BE_DEFINED)](https://github.com/Orange-OpenSource/hurl/blob/master/CHANGELOG.md#5.0.1)
========================================================================================================================
[5.0.0 (2024-08-29)](https://github.com/Orange-OpenSource/hurl/blob/master/CHANGELOG.md#5.0.0)
========================================================================================================================

View File

@ -1,2 +1 @@
Response endpoint2
Response endpoint2

View File

@ -1,9 +1,10 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
# We test that --output truncates an existing file then appends it.
echo "Not a response" > build/output.bin
if (Test-Path build/output.bin) {
Remove-Item build/output.bin
}
hurl --output build/output.bin tests_ok/output.hurl tests_ok/output.hurl
hurl --output build/output.bin tests_ok/output.hurl
Write-Host (Get-Content build/output.bin -Raw) -NoNewLine

View File

@ -1,9 +1,7 @@
#!/bin/bash
set -Eeuo pipefail
# We test that --output truncates an existing file then appends it.
rm -f build/output.bin
echo "Not a response" > build/output.bin
hurl --output build/output.bin tests_ok/output.hurl tests_ok/output.hurl
hurl --output build/output.bin tests_ok/output.hurl
cat build/output.bin

View File

@ -0,0 +1,8 @@
# Test the option --output (see <https://hurl.dev/docs/manual.html#output>)
POST http://localhost:8000/output/endpoint1
{ "user": "bob" }
HTTP 200
GET http://localhost:8000/output/endpoint2
HTTP 200

View File

@ -0,0 +1,2 @@
Response endpoint2
Response endpoint2

View File

@ -0,0 +1,9 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
# We test that --output truncates an existing file then appends it.
echo "Not a response" > build/output_existing.bin
hurl --output build/output_existing.bin tests_ok/output_existing.hurl tests_ok/output_existing.hurl
Write-Host (Get-Content build/output_existing.bin -Raw) -NoNewLine

View File

@ -0,0 +1,9 @@
#!/bin/bash
set -Eeuo pipefail
# We test that --output truncates an existing file then appends it.
echo "Not a response" > build/output_existing.bin
hurl --output build/output_existing.bin tests_ok/output_existing.hurl tests_ok/output_existing.hurl
cat build/output_existing.bin

View File

@ -64,6 +64,7 @@ impl Output {
Output::Stdout => stdout.write_all(bytes)?,
Output::File(filename) => {
let mut file = OpenOptions::new()
.create(true)
.write(true)
.append(append)
.open(filename)?;