Skip to content

Commit

Permalink
Set variable url automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix committed Oct 14, 2022
1 parent f96998b commit 0df7f14
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
7 changes: 6 additions & 1 deletion integration/tests_ok/redirect.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirected</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">variable</span> <span class="string">"self_request_url"</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
Expand All @@ -14,6 +16,8 @@
<span class="line"><span class="string">location</span><span>:</span> <span class="boolean">true</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">variable</span> <span class="string">"self_request_url"</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
Expand All @@ -28,10 +32,11 @@
<span class="line"><span class="string">location</span><span>:</span> <span class="boolean">true</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">variable</span> <span class="string">"self_request_url"</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="line"></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
</code></pre>
7 changes: 6 additions & 1 deletion integration/tests_ok/redirect.hurl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
GET http://localhost:8000/redirected
HTTP/1.0 200
[Asserts]
variable "self_request_url" == "http://localhost:8000/redirected"
```Redirected```


Expand All @@ -14,6 +16,8 @@ GET http://localhost:8000/redirect-absolute
location: true

HTTP/1.0 200
[Asserts]
variable "self_request_url" == "http://localhost:8000/redirected"
```Redirected```


Expand All @@ -28,9 +32,10 @@ GET http://localhost:8000/redirect-relative
location: true

HTTP/1.0 200
[Asserts]
variable "self_request_url" == "http://localhost:8000/redirected"
```Redirected```





2 changes: 1 addition & 1 deletion integration/tests_ok/redirect.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/redirected"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"http://localhost:8000/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}}]}
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/redirected"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"variable","name":"self_request_url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"http://localhost:8000/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"variable","name":"self_request_url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"variable","name":"self_request_url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}}]}
11 changes: 10 additions & 1 deletion packages/hurl/src/runner/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn run(
};

// We runs capture and asserts on the last HTTP request/response chains.
let (_, http_response) = calls.last().unwrap();
let (http_request, http_response) = calls.last().unwrap();
let calls: Vec<Call> = calls
.iter()
.map(|(req, resp)| Call {
Expand Down Expand Up @@ -140,6 +140,15 @@ pub fn run(
};

// Update variables now!

// Set variables implicitly
// For the time-being, the variable self_request_url should only be used by the query <url>
// In the long-term, we should set a request object with several fields that will be accessed
// with the expression {{request.url}}
variables.insert(
"self_request_url".to_string(),
Value::String(http_request.url.clone()),
);
for c in captures.iter() {
variables.insert(c.name.clone(), c.value.clone());
}
Expand Down

0 comments on commit 0df7f14

Please sign in to comment.