mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-24 11:32:00 +03:00
Add duration query
This commit is contained in:
parent
91f0d244bf
commit
c3b6f85fde
@ -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>
|
@ -4,5 +4,8 @@ HTTP/1.0 200
|
|||||||
Content-Type: application/octet-stream
|
Content-Type: application/octet-stream
|
||||||
Content-Length: 536870912
|
Content-Length: 536870912
|
||||||
|
|
||||||
|
[Asserts]
|
||||||
|
duration lessThanOrEquals 10000 # Duration in ms
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"}}]}}]}
|
@ -200,6 +200,9 @@ pub fn eval_query(
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QueryValue::Duration {} => Ok(Some(Value::Integer(
|
||||||
|
http_response.duration.as_millis() as i64
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,6 +322,7 @@ pub enum QueryValue {
|
|||||||
space0: Whitespace,
|
space0: Whitespace,
|
||||||
name: Template,
|
name: Template,
|
||||||
},
|
},
|
||||||
|
Duration {},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
@ -55,6 +55,7 @@ fn query_value(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
|||||||
jsonpath_query,
|
jsonpath_query,
|
||||||
regex_query,
|
regex_query,
|
||||||
variable_query,
|
variable_query,
|
||||||
|
duration_query,
|
||||||
],
|
],
|
||||||
reader,
|
reader,
|
||||||
)
|
)
|
||||||
@ -148,6 +149,11 @@ fn regex_subquery(reader: &mut Reader) -> ParseResult<'static, SubqueryValue> {
|
|||||||
Ok(SubqueryValue::Regex { space0, expr })
|
Ok(SubqueryValue::Regex { space0, expr })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn duration_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||||
|
try_literal("duration", reader)?;
|
||||||
|
Ok(QueryValue::Duration {})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -372,6 +372,9 @@ impl Htmlable for QueryValue {
|
|||||||
format!("<span class=\"string\">\"{}\"</span>", name.to_html()).as_str(),
|
format!("<span class=\"string\">\"{}\"</span>", name.to_html()).as_str(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
QueryValue::Duration {} => {
|
||||||
|
buffer.push_str("<span class=\"query-type\">duration</span>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
@ -287,6 +287,9 @@ impl ToJson for QueryValue {
|
|||||||
attributes.push(("type".to_string(), JValue::String("variable".to_string())));
|
attributes.push(("type".to_string(), JValue::String("variable".to_string())));
|
||||||
attributes.push(("name".to_string(), JValue::String(name.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)
|
JValue::Object(attributes)
|
||||||
}
|
}
|
||||||
|
@ -467,6 +467,7 @@ impl Tokenizable for Query {
|
|||||||
add_tokens(&mut tokens, space0.tokenize());
|
add_tokens(&mut tokens, space0.tokenize());
|
||||||
add_tokens(&mut tokens, name.tokenize());
|
add_tokens(&mut tokens, name.tokenize());
|
||||||
}
|
}
|
||||||
|
QueryValue::Duration {} => tokens.push(Token::QueryType(String::from("duration"))),
|
||||||
}
|
}
|
||||||
tokens
|
tokens
|
||||||
}
|
}
|
||||||
|
@ -305,6 +305,7 @@ impl Lintable<QueryValue> for QueryValue {
|
|||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
space0: one_whitespace(),
|
space0: one_whitespace(),
|
||||||
},
|
},
|
||||||
|
QueryValue::Duration {} => QueryValue::Duration {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user