Skip to content

Commit

Permalink
Update variables hash while iterating and evaluating the capture sect…
Browse files Browse the repository at this point in the history
…ion (instead of updating it once with all the variables).
  • Loading branch information
jcamiel committed Dec 1, 2022
1 parent 3eaa74c commit 51b196e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 0 additions & 4 deletions packages/hurl/src/runner/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ pub fn run(
},
};

// Update variables now!
for c in captures.iter() {
variables.insert(c.name.clone(), c.value.clone());
}
if !captures.is_empty() {
logger.debug_important("Captures:");
for c in captures.iter() {
Expand Down
10 changes: 7 additions & 3 deletions packages/hurl/src/runner/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,18 @@ fn eval_implicit_body_asserts(
}
}

/// Evaluates captures from this HTTP `http_response`, given a set of `variables`.
pub fn eval_captures(
response: &Response,
http_response: &http::Response,
variables: &HashMap<String, Value>,
variables: &mut HashMap<String, Value>,
) -> Result<Vec<CaptureResult>, Error> {
let mut captures = vec![];
for capture in response.captures().iter() {
let capture_result = eval_capture(capture, variables, http_response)?;
// Update variables now so the captures set is ready in case
// the next captures reference this new variable.
variables.insert(capture_result.name.clone(), capture_result.value.clone());
captures.push(capture_result);
}
Ok(captures)
Expand Down Expand Up @@ -388,12 +392,12 @@ mod tests {

#[test]
pub fn test_eval_captures() {
let variables = HashMap::new();
let mut variables = HashMap::new();
assert_eq!(
eval_captures(
&user_response(),
&http::xml_two_users_http_response(),
&variables,
&mut variables,
)
.unwrap(),
vec![CaptureResult {
Expand Down

0 comments on commit 51b196e

Please sign in to comment.