mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-17 08:47:44 +03:00
Accept mutiple --variables-file options
This commit is contained in:
parent
748a2084c5
commit
d39e975c05
@ -1,3 +1,3 @@
|
||||
curl -H 'Name: Jennifer' -H 'Age: 30' -H 'Height: 1.7' -H 'Female: true' -H 'Id: 123' -H 'A_Null: null' -H 'Country: Italy' -H 'Planet: The Earth' -H 'Content-Type: application/json' --data $'{\n "name": "Jennifer",\n "age": 30,\n "height": 1.7,\n "female": true,\n "id": "123",\n "a_null": null,\n "country": "Italy",\n "planet": "The Earth"\n}' 'http://localhost:8000/variables'
|
||||
curl -H 'Name: Jennifer' -H 'Age: 30' -H 'Height: 1.7' -H 'Female: true' -H 'Id: 123' -H 'A_Null: null' -H 'Country: Italy' -H 'Planet: The Earth' -H 'Galaxy: Milky Way' -H 'Content-Type: application/json' --data $'{\n "name": "Jennifer",\n "age": 30,\n "height": 1.7,\n "female": true,\n "id": "123",\n "a_null": null,\n "country": "Italy",\n "planet": "The Earth",\n "galaxy": "Milky Way"\n}' 'http://localhost:8000/variables'
|
||||
curl 'http://localhost:8000/variable/country'
|
||||
curl 'http://localhost:8000/variable/planet'
|
||||
|
@ -13,6 +13,7 @@
|
||||
<span class="line"><span class="string">A_Null</span><span>:</span> <span class="string">{{a_null}}</span></span>
|
||||
<span class="line"><span class="string">Country</span><span>:</span> <span class="string">{{country}}</span></span>
|
||||
<span class="line"><span class="string">Planet</span><span>:</span> <span class="string">{{planet}}</span></span>
|
||||
<span class="line"><span class="string">Galaxy</span><span>:</span> <span class="string">{{galaxy}}</span></span>
|
||||
<span class="line section-header">[Options]</span>
|
||||
<span class="line"><span class="string">variable</span><span>:</span> country<span>=</span><span class="string">Italy</span></span>
|
||||
<span class="line"><span class="string">variable</span><span>:</span> planet<span>=</span><span class="string">The Earth</span></span>
|
||||
@ -24,7 +25,8 @@
|
||||
<span class="line"> "id": "{{my-id}}",</span>
|
||||
<span class="line"> "a_null": {{a_null}},</span>
|
||||
<span class="line"> "country": "{{country}}",</span>
|
||||
<span class="line"> "planet": "{{planet}}"</span>
|
||||
<span class="line"> "planet": "{{planet}}",</span>
|
||||
<span class="line"> "galaxy": "{{galaxy}}"</span>
|
||||
<span class="line">}</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
@ -37,6 +39,7 @@
|
||||
<span class="line"><span class="query-type">variable</span> <span class="string">"my-id"</span> <span class="predicate-type">==</span> <span class="string">"123"</span></span>
|
||||
<span class="line"><span class="query-type">variable</span> <span class="string">"country"</span> <span class="predicate-type">==</span> <span class="string">"Italy"</span></span>
|
||||
<span class="line"><span class="query-type">variable</span> <span class="string">"planet"</span> <span class="predicate-type">==</span> <span class="string">"The Earth"</span></span>
|
||||
<span class="line"><span class="query-type">variable</span> <span class="string">"galaxy"</span> <span class="predicate-type">==</span> <span class="string">"Milky Way"</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"></span><span class="comment"># `country` and `planet` variable are still available</span>
|
||||
|
@ -13,6 +13,7 @@ Id: {{my-id}}
|
||||
A_Null: {{a_null}}
|
||||
Country: {{country}}
|
||||
Planet: {{planet}}
|
||||
Galaxy: {{galaxy}}
|
||||
[Options]
|
||||
variable: country=Italy
|
||||
variable: planet=The Earth
|
||||
@ -24,7 +25,8 @@ variable: planet=The Earth
|
||||
"id": "{{my-id}}",
|
||||
"a_null": {{a_null}},
|
||||
"country": "{{country}}",
|
||||
"planet": "{{planet}}"
|
||||
"planet": "{{planet}}",
|
||||
"galaxy": "{{galaxy}}"
|
||||
}
|
||||
|
||||
HTTP 200
|
||||
@ -37,6 +39,7 @@ variable "a_null" == null
|
||||
variable "my-id" == "123"
|
||||
variable "country" == "Italy"
|
||||
variable "planet" == "The Earth"
|
||||
variable "galaxy" == "Milky Way"
|
||||
|
||||
|
||||
# `country` and `planet` variable are still available
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/variables","headers":[{"name":"Name","value":"{{name}}"},{"name":"Age","value":"{{age}}"},{"name":"Height","value":"{{height}}"},{"name":"Female","value":"{{female}}"},{"name":"Id","value":"{{my-id}}"},{"name":"A_Null","value":"{{a_null}}"},{"name":"Country","value":"{{country}}"},{"name":"Planet","value":"{{planet}}"}],"body":{"type":"json","value":{"name":"{{name}}","age":"{{age}}","height":"{{height}}","female":"{{female}}","id":"{{my-id}}","a_null":"{{a_null}}","country":"{{country}}","planet":"{{planet}}"}}},"response":{"status":200,"asserts":[{"query":{"type":"variable","name":"name"},"predicate":{"type":"equal","value":"Jennifer"}},{"query":{"type":"variable","name":"female"},"predicate":{"type":"equal","value":true}},{"query":{"type":"variable","name":"age"},"predicate":{"type":"equal","value":30}},{"query":{"type":"variable","name":"height"},"predicate":{"type":"equal","value":1.70}},{"query":{"type":"variable","name":"a_null"},"predicate":{"type":"equal","value":null}},{"query":{"type":"variable","name":"my-id"},"predicate":{"type":"equal","value":"123"}},{"query":{"type":"variable","name":"country"},"predicate":{"type":"equal","value":"Italy"}},{"query":{"type":"variable","name":"planet"},"predicate":{"type":"equal","value":"The Earth"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/variable/country"},"response":{"status":200,"body":{"type":"text","value":"{{country}}"}}},{"request":{"method":"GET","url":"http://localhost:8000/variable/planet"},"response":{"status":200,"body":{"type":"text","value":"{{planet}}"}}}]}
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/variables","headers":[{"name":"Name","value":"{{name}}"},{"name":"Age","value":"{{age}}"},{"name":"Height","value":"{{height}}"},{"name":"Female","value":"{{female}}"},{"name":"Id","value":"{{my-id}}"},{"name":"A_Null","value":"{{a_null}}"},{"name":"Country","value":"{{country}}"},{"name":"Planet","value":"{{planet}}"},{"name":"Galaxy","value":"{{galaxy}}"}],"body":{"type":"json","value":{"name":"{{name}}","age":"{{age}}","height":"{{height}}","female":"{{female}}","id":"{{my-id}}","a_null":"{{a_null}}","country":"{{country}}","planet":"{{planet}}","galaxy":"{{galaxy}}"}}},"response":{"status":200,"asserts":[{"query":{"type":"variable","name":"name"},"predicate":{"type":"equal","value":"Jennifer"}},{"query":{"type":"variable","name":"female"},"predicate":{"type":"equal","value":true}},{"query":{"type":"variable","name":"age"},"predicate":{"type":"equal","value":30}},{"query":{"type":"variable","name":"height"},"predicate":{"type":"equal","value":1.70}},{"query":{"type":"variable","name":"a_null"},"predicate":{"type":"equal","value":null}},{"query":{"type":"variable","name":"my-id"},"predicate":{"type":"equal","value":"123"}},{"query":{"type":"variable","name":"country"},"predicate":{"type":"equal","value":"Italy"}},{"query":{"type":"variable","name":"planet"},"predicate":{"type":"equal","value":"The Earth"}},{"query":{"type":"variable","name":"galaxy"},"predicate":{"type":"equal","value":"Milky Way"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/variable/country"},"response":{"status":200,"body":{"type":"text","value":"{{country}}"}}},{"request":{"method":"GET","url":"http://localhost:8000/variable/planet"},"response":{"status":200,"body":{"type":"text","value":"{{planet}}"}}}]}
|
||||
|
@ -1,4 +1,6 @@
|
||||
--variables-file
|
||||
tests_ok/variables.properties
|
||||
tests_ok/variables0.properties
|
||||
--variables-file
|
||||
tests_ok/variables1.properties
|
||||
--variable
|
||||
female=true
|
||||
|
@ -14,6 +14,7 @@ def variables():
|
||||
assert request.headers["A_null"] == "null"
|
||||
assert request.headers["Country"] == "Italy"
|
||||
assert request.headers["Planet"] == "The Earth"
|
||||
assert request.headers["Galaxy"] == "Milky Way"
|
||||
|
||||
s = request.data.decode("utf-8")
|
||||
data = json.loads(s)
|
||||
@ -25,6 +26,7 @@ def variables():
|
||||
assert data["a_null"] is None
|
||||
assert data["country"] == "Italy"
|
||||
assert data["planet"] == "The Earth"
|
||||
assert data["galaxy"] == "Milky Way"
|
||||
return ""
|
||||
|
||||
|
||||
|
3
integration/tests_ok/variables1.properties
Normal file
3
integration/tests_ok/variables1.properties
Normal file
@ -0,0 +1,3 @@
|
||||
# Variables for hurl
|
||||
galaxy=Milky Way
|
||||
|
@ -392,6 +392,7 @@ pub fn app(version: &str) -> Command {
|
||||
.long("variables-file")
|
||||
.value_name("FILE")
|
||||
.help("Define a properties file in which you define your variables")
|
||||
.action(ArgAction::Append)
|
||||
.num_args(1)
|
||||
)
|
||||
.arg(
|
||||
@ -588,31 +589,37 @@ fn variables(matches: &ArgMatches) -> Result<HashMap<String, Value>, CliError> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(filename) = get::<String>(matches, "variables_file") {
|
||||
let path = Path::new(&filename);
|
||||
if !path.exists() {
|
||||
return Err(CliError {
|
||||
message: format!("Properties file {} does not exist", path.display()),
|
||||
});
|
||||
}
|
||||
|
||||
let file = File::open(path).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
for (index, line) in reader.lines().enumerate() {
|
||||
let line = match line {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(CliError {
|
||||
message: format!("Can not parse line {} of {}", index + 1, path.display()),
|
||||
});
|
||||
}
|
||||
};
|
||||
let line = line.trim();
|
||||
if line.starts_with('#') || line.is_empty() {
|
||||
continue;
|
||||
if let Some(filenames) = get_strings(matches, "variables_file") {
|
||||
for f in filenames.iter() {
|
||||
let path = Path::new(&f);
|
||||
if !path.exists() {
|
||||
return Err(CliError {
|
||||
message: format!("Properties file {} does not exist", path.display()),
|
||||
});
|
||||
}
|
||||
|
||||
let file = File::open(path).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
for (index, line) in reader.lines().enumerate() {
|
||||
let line = match line {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(CliError {
|
||||
message: format!(
|
||||
"Can not parse line {} of {}",
|
||||
index + 1,
|
||||
path.display()
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
let line = line.trim();
|
||||
if line.starts_with('#') || line.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let (name, value) = cli::parse_variable(line)?;
|
||||
variables.insert(name.to_string(), value);
|
||||
}
|
||||
let (name, value) = cli::parse_variable(line)?;
|
||||
variables.insert(name.to_string(), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user