Add option skip

This commit is contained in:
Fabrice Reix 2023-10-20 08:47:28 +02:00
parent e824a46998
commit ada42acb32
No known key found for this signature in database
GPG Key ID: BF5213154B2E7155
13 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,118 @@
* ------------------------------------------------------------------------------
* Executing entry 1
*
* Cookie store:
*
* Request:
* GET http://localhost:8000/skip/init
*
* Request can be run with the following curl command:
* curl 'http://localhost:8000/skip/init'
*
> GET /skip/init HTTP/1.1
> Host: localhost:8000
> Accept: */*
> User-Agent: hurl/~~~
>
* Response: (received 1 bytes in ~~~ ms)
*
< HTTP/1.1 200 OK
< Server: Werkzeug/~~~ Python/~~~
< Date: ~~~
< Content-Type: text/html; charset=utf-8
< Content-Length: 1
< Server: Flask Server
< Connection: close
<
*
* ------------------------------------------------------------------------------
* Executing entry 2
*
* Entry options:
* skip: true
* Entry 2 has been skipped
*
* ------------------------------------------------------------------------------
* Executing entry 3
*
* Cookie store:
*
* Request:
* GET http://localhost:8000/skip/get
*
* Request can be run with the following curl command:
* curl 'http://localhost:8000/skip/get'
*
> GET /skip/get HTTP/1.1
> Host: localhost:8000
> Accept: */*
> User-Agent: hurl/~~~
>
* Response: (received 1 bytes in ~~~ ms)
*
< HTTP/1.1 200 OK
< Server: Werkzeug/~~~ Python/~~~
< Date: ~~~
< Content-Type: text/html; charset=utf-8
< Content-Length: 1
< Server: Flask Server
< Connection: close
<
*
* ------------------------------------------------------------------------------
* Executing entry 4
*
* Entry options:
* skip: false
*
* Cookie store:
*
* Request:
* GET http://localhost:8000/skip/increment
*
* Request can be run with the following curl command:
* curl 'http://localhost:8000/skip/increment'
*
> GET /skip/increment HTTP/1.1
> Host: localhost:8000
> Accept: */*
> User-Agent: hurl/~~~
>
* Response: (received 1 bytes in ~~~ ms)
*
< HTTP/1.1 200 OK
< Server: Werkzeug/~~~ Python/~~~
< Date: ~~~
< Content-Type: text/html; charset=utf-8
< Content-Length: 1
< Server: Flask Server
< Connection: close
<
*
* ------------------------------------------------------------------------------
* Executing entry 5
*
* Cookie store:
*
* Request:
* GET http://localhost:8000/skip/get
*
* Request can be run with the following curl command:
* curl 'http://localhost:8000/skip/get'
*
> GET /skip/get HTTP/1.1
> Host: localhost:8000
> Accept: */*
> User-Agent: hurl/~~~
>
* Response: (received 1 bytes in ~~~ ms)
*
< HTTP/1.1 200 OK
< Server: Werkzeug/~~~ Python/~~~
< Date: ~~~
< Content-Type: text/html; charset=utf-8
< Content-Length: 1
< Server: Flask Server
< Connection: close
<
*

View File

@ -0,0 +1,23 @@
GET http://localhost:8000/skip/init
HTTP 200
`0`
GET http://localhost:8000/skip/increment
[Options]
skip: true
HTTP 200
`whatever`
GET http://localhost:8000/skip/get
HTTP 200
`0`
GET http://localhost:8000/skip/increment
[Options]
skip: false
HTTP 200
`1`
GET http://localhost:8000/skip/get
HTTP 200
`1`

View File

@ -0,0 +1,3 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl tests_ok/skip.hurl --verbose

View File

@ -0,0 +1,25 @@
# coding=utf-8
from app import app
counter = 0
@app.route("/skip/init")
def skip_init():
global counter
counter = 0
return str(counter)
@app.route("/skip/increment")
def skip_increment():
global counter
counter = counter + 1
return str(counter)
@app.route("/skip/get")
def skip_get():
global counter
return str(counter)

3
integration/tests_ok/skip.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
set -Eeuo pipefail
hurl tests_ok/skip.hurl --verbose

View File

@ -136,6 +136,14 @@ pub fn run(
let options = options::get_entry_options(entry, runner_options, &mut variables, &logger);
let entry_result = match &options {
Ok(options) => {
if options.skip {
logger
.debug_important(format!("Entry {entry_index} has been skipped").as_str());
logger.debug("");
entry_index += 1;
continue;
}
let delay = options.delay;
let delay_ms = delay.as_millis();
if delay_ms > 0 {

View File

@ -176,6 +176,10 @@ pub fn get_entry_options(
let value = eval_natural_option(value, variables)?;
runner_options.retry_interval = Duration::from_millis(value)
}
OptionKind::Skip(value) => {
let value = eval_boolean_option(value, variables)?;
runner_options.skip = value
}
OptionKind::Variable(VariableDefinition { name, value, .. }) => {
let value = eval_variable_value(value, variables)?;
variables.insert(name.clone(), value);

View File

@ -48,6 +48,7 @@ pub struct RunnerOptionsBuilder {
resolves: Vec<String>,
retry: Retry,
retry_interval: Duration,
skip: bool,
ssl_no_revoke: bool,
timeout: Duration,
to_entry: Option<usize>,
@ -83,6 +84,7 @@ impl Default for RunnerOptionsBuilder {
resolves: vec![],
retry: Retry::None,
retry_interval: Duration::from_millis(1000),
skip: false,
ssl_no_revoke: false,
timeout: Duration::from_secs(300),
to_entry: None,
@ -342,6 +344,7 @@ impl RunnerOptionsBuilder {
resolves: self.resolves.clone(),
retry: self.retry,
retry_interval: self.retry_interval,
skip: self.skip,
ssl_no_revoke: self.ssl_no_revoke,
timeout: self.timeout,
to_entry: self.to_entry,
@ -378,6 +381,7 @@ pub struct RunnerOptions {
pub(crate) resolves: Vec<String>,
pub(crate) retry: Retry,
pub(crate) retry_interval: Duration,
pub(crate) skip: bool,
pub(crate) ssl_no_revoke: bool,
pub(crate) timeout: Duration,
pub(crate) to_entry: Option<usize>,

View File

@ -737,6 +737,7 @@ pub enum OptionKind {
Resolve(Template),
Retry(RetryOption),
RetryInterval(NaturalOption),
Skip(BooleanOption),
Variable(VariableDefinition),
Verbose(BooleanOption),
VeryVerbose(BooleanOption),
@ -766,6 +767,7 @@ impl OptionKind {
OptionKind::Resolve(_) => "resolve",
OptionKind::Retry(_) => "retry",
OptionKind::RetryInterval(_) => "retry-interval",
OptionKind::Skip(_) => "skip",
OptionKind::Variable(_) => "variable",
OptionKind::Verbose(_) => "verbose",
OptionKind::VeryVerbose(_) => "very-verbose",
@ -795,6 +797,7 @@ impl OptionKind {
OptionKind::Resolve(value) => value.to_string(),
OptionKind::Retry(value) => value.to_string(),
OptionKind::RetryInterval(value) => value.to_string(),
OptionKind::Skip(value) => value.to_string(),
OptionKind::Variable(VariableDefinition { name, value, .. }) => {
format!("{name}={value}")
}

View File

@ -234,6 +234,7 @@ impl HtmlFormatter {
OptionKind::Resolve(value) => self.fmt_template(value),
OptionKind::Retry(value) => self.fmt_retry_option(value),
OptionKind::RetryInterval(value) => self.fmt_natural_option(value),
OptionKind::Skip(value) => self.fmt_bool_option(value),
OptionKind::Variable(value) => self.fmt_variable_definition(value),
OptionKind::Verbose(value) => self.fmt_bool_option(value),
OptionKind::VeryVerbose(value) => self.fmt_bool_option(value),

View File

@ -54,6 +54,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<EntryOption> {
"resolve" => option_resolve(reader)?,
"retry" => option_retry(reader)?,
"retry-interval" => option_retry_interval(reader)?,
"skip" => option_skip(reader)?,
"variable" => option_variable(reader)?,
"verbose" => option_verbose(reader)?,
"very-verbose" => option_very_verbose(reader)?,
@ -182,6 +183,11 @@ fn option_retry_interval(reader: &mut Reader) -> ParseResult<OptionKind> {
Ok(OptionKind::RetryInterval(value))
}
fn option_skip(reader: &mut Reader) -> ParseResult<OptionKind> {
let value = nonrecover(boolean_option, reader)?;
Ok(OptionKind::Skip(value))
}
fn option_variable(reader: &mut Reader) -> ParseResult<OptionKind> {
let value = variable_definition(reader)?;
Ok(OptionKind::Variable(value))

View File

@ -301,6 +301,7 @@ impl ToJson for EntryOption {
OptionKind::Resolve(value) => JValue::String(value.to_string()),
OptionKind::Retry(value) => JValue::Number(value.to_string()),
OptionKind::RetryInterval(value) => JValue::Number(value.to_string()),
OptionKind::Skip(value) => value.to_json(),
OptionKind::Variable(value) => {
JValue::String(format!("{}={}", value.name, value.value))
}

View File

@ -897,6 +897,7 @@ impl Tokenizable for OptionKind {
OptionKind::Resolve(value) => value.tokenize(),
OptionKind::Retry(value) => value.tokenize(),
OptionKind::RetryInterval(value) => value.tokenize(),
OptionKind::Skip(value) => value.tokenize(),
OptionKind::Variable(value) => value.tokenize(),
OptionKind::Verbose(value) => value.tokenize(),
OptionKind::VeryVerbose(value) => value.tokenize(),