mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 00:44:55 +03:00
Fix filename templatization bug under certains conditions.
This commit is contained in:
parent
87eb7222dd
commit
9444d6a058
@ -7,13 +7,14 @@ def output_endpoint1():
|
||||
assert request.headers["Content-Type"] == "application/json"
|
||||
s = request.data.decode("utf-8")
|
||||
assert s == '{ "user": "bob" }'
|
||||
return app.response_class(
|
||||
headers={"date": "DATE1"}, response="Response endpoint1\n"
|
||||
)
|
||||
return "Response endpoint1\n"
|
||||
|
||||
|
||||
@app.route("/output/endpoint2")
|
||||
def output_endpoint2():
|
||||
return app.response_class(
|
||||
headers={"date": "DATE2"}, response="Response endpoint2\n"
|
||||
)
|
||||
return "Response endpoint2\n"
|
||||
|
||||
|
||||
@app.route("/output/endpoint3")
|
||||
def output_endpoint3():
|
||||
return "Response endpoint3\n"
|
||||
|
@ -1,2 +1,3 @@
|
||||
curl --header 'Content-Type: application/json' --data '{ "user": "bob" }' --output build/../build/output_request_1.bin 'http://localhost:8000/output/endpoint1'
|
||||
curl 'http://localhost:8000/output/endpoint2'
|
||||
curl 'http://localhost:8000/output/endpoint3'
|
||||
|
@ -4,5 +4,14 @@ output: ../build/output_request_1.bin
|
||||
{ "user": "bob" }
|
||||
HTTP 200
|
||||
|
||||
|
||||
# output options supports templating
|
||||
GET http://localhost:8000/output/endpoint2
|
||||
[Options]
|
||||
variable: filename=output_request_2
|
||||
output: ../build/{{filename}}.bin
|
||||
HTTP 200
|
||||
|
||||
|
||||
GET http://localhost:8000/output/endpoint3
|
||||
HTTP 200
|
||||
|
@ -1 +1,2 @@
|
||||
Response endpoint1
|
||||
Response endpoint2
|
||||
|
@ -3,5 +3,9 @@ $ErrorActionPreference = 'Stop'
|
||||
if (Test-Path build/output_request_1.bin) {
|
||||
Remove-Item build/output_request_1.bin
|
||||
}
|
||||
if (Test-Path build/output_request_2.bin) {
|
||||
Remove-Item build/output_request_2.bin
|
||||
}
|
||||
hurl --no-output --file-root build tests_ok/output_option.hurl
|
||||
Write-Host (Get-Content build/output_request_1.bin -Raw) -NoNewLine
|
||||
Write-Host (Get-Content build/output_request_2.bin -Raw) -NoNewLine
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -Eeuo pipefail
|
||||
rm -f build/output_request_1.bin
|
||||
rm -f build/output_request_2.bin
|
||||
hurl --no-output --file-root build tests_ok/output_option.hurl
|
||||
cat build/output_request_1.bin
|
||||
cat build/output_request_1.bin build/output_request_2.bin
|
||||
|
@ -27,6 +27,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<Template> {
|
||||
|
||||
let mut elements = vec![];
|
||||
loop {
|
||||
let start = reader.state;
|
||||
match template(reader) {
|
||||
Ok(expr) => {
|
||||
let element = TemplateElement::Expression(expr);
|
||||
@ -210,4 +211,69 @@ mod tests {
|
||||
assert_eq!(error.inner, ParseError::Filename);
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filename_with_variables() {
|
||||
let mut reader = Reader::new("foo_{{bar}}");
|
||||
assert_eq!(
|
||||
parse(&mut reader).unwrap(),
|
||||
Template {
|
||||
delimiter: None,
|
||||
elements: vec![
|
||||
TemplateElement::String {
|
||||
value: "foo_".to_string(),
|
||||
encoded: "foo_".to_string(),
|
||||
},
|
||||
TemplateElement::Expression(Expr {
|
||||
space0: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 7)),
|
||||
},
|
||||
variable: Variable {
|
||||
name: "bar".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)),
|
||||
},
|
||||
space1: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 10)),
|
||||
},
|
||||
})
|
||||
],
|
||||
source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 12)),
|
||||
}
|
||||
);
|
||||
|
||||
let mut reader = Reader::new("foo_{{bar}}_baz");
|
||||
assert_eq!(
|
||||
parse(&mut reader).unwrap(),
|
||||
Template {
|
||||
delimiter: None,
|
||||
elements: vec![
|
||||
TemplateElement::String {
|
||||
value: "foo_".to_string(),
|
||||
encoded: "foo_".to_string(),
|
||||
},
|
||||
TemplateElement::Expression(Expr {
|
||||
space0: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 7)),
|
||||
},
|
||||
variable: Variable {
|
||||
name: "bar".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)),
|
||||
},
|
||||
space1: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 10)),
|
||||
},
|
||||
}),
|
||||
TemplateElement::String {
|
||||
value: "_baz".to_string(),
|
||||
encoded: "_baz".to_string(),
|
||||
},
|
||||
],
|
||||
source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 16)),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ impl Tokenizable for Template {
|
||||
if let Some(d) = self.delimiter {
|
||||
tokens.push(Token::StringDelimiter(d.to_string()));
|
||||
}
|
||||
for element in self.elements.clone() {
|
||||
for element in &self.elements {
|
||||
tokens.append(&mut element.tokenize());
|
||||
}
|
||||
if let Some(d) = self.delimiter {
|
||||
|
Loading…
Reference in New Issue
Block a user