Add duration query

This commit is contained in:
Fabrice Reix 2020-11-22 08:55:07 +01:00
parent 91f0d244bf
commit c3b6f85fde
10 changed files with 23 additions and 2 deletions

View File

@ -1 +1 @@
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/large</span></span></div><div class="response"><span class="line"></span><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">application/octet-stream</span></span><span class="line"><span class="string">Content-Length</span><span>:</span> <span class="string">536870912</span></span></div></div><span class="line"></span><span class="line"></span><span class="line"></span></div>
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/large</span></span></div><div class="response"><span class="line"></span><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">application/octet-stream</span></span><span class="line"><span class="string">Content-Length</span><span>:</span> <span class="string">536870912</span></span><span class="line"></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">duration</span> <span class="predicate-type">less-than-or-equal</span> <span class="number">10000</span></span></div></div><span class="line"></span><span class="line"></span><span class="line"></span></div>

View File

@ -4,5 +4,8 @@ HTTP/1.0 200
Content-Type: application/octet-stream
Content-Length: 536870912
[Asserts]
duration lessThanOrEquals 10000 # Duration in ms

View File

@ -1 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/large"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"application/octet-stream"},{"name":"Content-Length","value":"536870912"}]}}]}
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/large"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"application/octet-stream"},{"name":"Content-Length","value":"536870912"}],"asserts":[{"query":{"type":"duration"},"predicate":{"type":"less-than-or-equal","value":"10000"}}]}}]}

View File

@ -200,6 +200,9 @@ pub fn eval_query(
Ok(None)
}
}
QueryValue::Duration {} => Ok(Some(Value::Integer(
http_response.duration.as_millis() as i64
))),
}
}

View File

@ -322,6 +322,7 @@ pub enum QueryValue {
space0: Whitespace,
name: Template,
},
Duration {},
}
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -55,6 +55,7 @@ fn query_value(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
jsonpath_query,
regex_query,
variable_query,
duration_query,
],
reader,
)
@ -148,6 +149,11 @@ fn regex_subquery(reader: &mut Reader) -> ParseResult<'static, SubqueryValue> {
Ok(SubqueryValue::Regex { space0, expr })
}
fn duration_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
try_literal("duration", reader)?;
Ok(QueryValue::Duration {})
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -372,6 +372,9 @@ impl Htmlable for QueryValue {
format!("<span class=\"string\">\"{}\"</span>", name.to_html()).as_str(),
);
}
QueryValue::Duration {} => {
buffer.push_str("<span class=\"query-type\">duration</span>");
}
}
buffer
}

View File

@ -287,6 +287,9 @@ impl ToJson for QueryValue {
attributes.push(("type".to_string(), JValue::String("variable".to_string())));
attributes.push(("name".to_string(), JValue::String(name.to_string())));
}
QueryValue::Duration {} => {
attributes.push(("type".to_string(), JValue::String("duration".to_string())));
}
};
JValue::Object(attributes)
}

View File

@ -467,6 +467,7 @@ impl Tokenizable for Query {
add_tokens(&mut tokens, space0.tokenize());
add_tokens(&mut tokens, name.tokenize());
}
QueryValue::Duration {} => tokens.push(Token::QueryType(String::from("duration"))),
}
tokens
}

View File

@ -305,6 +305,7 @@ impl Lintable<QueryValue> for QueryValue {
name: name.clone(),
space0: one_whitespace(),
},
QueryValue::Duration {} => QueryValue::Duration {},
}
}
}