Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tags for included files #167

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
override: true

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
uses: actions-rs/tarpaulin@v0.1.3
with:
version: '0.15.0'
args: '--ignore-tests'
9 changes: 9 additions & 0 deletions example/subtags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Example of a included file

---
- name: Fetch comments
request:
url: /api/comments.json
tags:
- tag_user

14 changes: 14 additions & 0 deletions example/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
base: 'http://localhost:9000'
iterations: 1
concurrency: 1

plan:
- name: Include comments
include: subtags.yml

- name: Tagged user request
request:
url: /api/users/70
tags:
- tag_user
8 changes: 4 additions & 4 deletions src/actions/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Request {
match context.get("base") {
Some(value) => {
if let Some(vs) = value.as_str() {
format!("{}{}", vs, interpolated_url)
format!("{vs}{interpolated_url}")
} else {
panic!("{} Wrong type 'base' variable!", "WARNING!".yellow().bold());
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Request {

if let Some(cookies) = context.get("cookies") {
let cookies: Map<String, Value> = serde_json::from_value(cookies.clone()).unwrap();
let cookie = cookies.iter().map(|(key, value)| format!("{}={}", key, value)).collect::<Vec<_>>().join(";");
let cookie = cookies.iter().map(|(key, value)| format!("{key}={value}")).collect::<Vec<_>>().join(";");

headers.insert(header::COOKIE, HeaderValue::from_str(&cookie).unwrap());
}
Expand Down Expand Up @@ -334,7 +334,7 @@ fn log_request(request: &reqwest::Request) {
write!(message, " {} {},", "URL:".bold(), request.url()).unwrap();
write!(message, " {} {},", "METHOD:".bold(), request.method()).unwrap();
write!(message, " {} {:?}", "HEADERS:".bold(), request.headers()).unwrap();
println!("{}", message);
println!("{message}");
}

fn log_message_response(response: &Option<reqwest::Response>, duration_ms: f64) -> String {
Expand All @@ -359,5 +359,5 @@ fn log_response(log_message_response: String, body: &Option<String>) {
if let Some(body) = body.as_ref() {
write!(message, " {} {:?}", "BODY:".bold(), body).unwrap()
}
println!("{}", message);
println!("{message}");
}
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn read_str_configuration(config_doc: &Yaml, interpolator: &interpolator::Interp
}
None => {
if config_doc[name].as_str().is_some() {
println!("Invalid {} value!", name);
println!("Invalid {name} value!");
}

default.to_owned()
Expand All @@ -85,7 +85,7 @@ fn read_i64_configuration(config_doc: &Yaml, interpolator: &interpolator::Interp
match value {
Some(value) => {
if value < 0 {
println!("Invalid negative {} value!", name);
println!("Invalid negative {name} value!");

default
} else {
Expand All @@ -94,7 +94,7 @@ fn read_i64_configuration(config_doc: &Yaml, interpolator: &interpolator::Interp
}
None => {
if config_doc[name].as_str().is_some() {
println!("Invalid {} value!", name);
println!("Invalid {name} value!");
}

default
Expand Down
8 changes: 6 additions & 2 deletions src/expandable/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub fn expand_from_filepath(parent_path: &str, benchmark: &mut Benchmark, access
let items = reader::read_yaml_doc_accessor(&docs[0], accessor);

for item in items {
if include::is_that_you(item) {
include::expand(parent_path, item, benchmark, tags);

continue;
}

if tags.should_skip_item(item) {
continue;
}
Expand All @@ -44,8 +50,6 @@ pub fn expand_from_filepath(parent_path: &str, benchmark: &mut Benchmark, access
multi_csv_request::expand(parent_path, item, benchmark);
} else if multi_file_request::is_that_you(item) {
multi_file_request::expand(parent_path, item, benchmark);
} else if include::is_that_you(item) {
include::expand(parent_path, item, benchmark, tags);
} else if actions::Delay::is_that_you(item) {
benchmark.push(Box::new(actions::Delay::new(item, None)));
} else if actions::Exec::is_that_you(item) {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ fn show_stats(list_reports: &[Vec<Report>], stats_option: bool, nanosec: bool, d
let requests_per_second = global_stats.total_requests as f64 / duration;

println!();
println!("{:width2$} {} {}", "Time taken for tests".yellow(), format!("{:.1}", duration).purple(), "seconds".purple(), width2 = 25);
println!("{:width2$} {} {}", "Time taken for tests".yellow(), format!("{duration:.1}").purple(), "seconds".purple(), width2 = 25);
println!("{:width2$} {}", "Total requests".yellow(), global_stats.total_requests.to_string().purple(), width2 = 25);
println!("{:width2$} {}", "Successful requests".yellow(), global_stats.successful_requests.to_string().purple(), width2 = 25);
println!("{:width2$} {}", "Failed requests".yellow(), global_stats.failed_requests.to_string().purple(), width2 = 25);
println!("{:width2$} {} {}", "Requests per second".yellow(), format!("{:.2}", requests_per_second).purple(), "[#/sec]".purple(), width2 = 25);
println!("{:width2$} {} {}", "Requests per second".yellow(), format!("{requests_per_second:.2}").purple(), "[#/sec]".purple(), width2 = 25);
println!("{:width2$} {}", "Median time per request".yellow(), format_time(global_stats.median_duration(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Average time per request".yellow(), format_time(global_stats.mean_duration(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Sample standard deviation".yellow(), format_time(global_stats.stdev_duration(), nanosec).purple(), width2 = 25);
Expand Down
6 changes: 3 additions & 3 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn read_yaml_doc_accessor<'a>(doc: &'a yaml_rust::Yaml, accessor: Option<&st
match doc[accessor_id].as_vec() {
Some(items) => items,
None => {
println!("Node missing on config: {}", accessor_id);
println!("Node missing on config: {accessor_id}");
println!("Exiting.");
std::process::exit(1)
}
Expand All @@ -58,7 +58,7 @@ pub fn read_file_as_yml_array(filepath: &str) -> yaml_rust::yaml::Array {
Ok(text) => {
items.push(yaml_rust::Yaml::String(text));
}
Err(e) => println!("error parsing line: {:?}", e),
Err(e) => println!("error parsing line: {e:?}"),
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn read_csv_file_as_yml(filepath: &str, quote: u8) -> yaml_rust::yaml::Array

items.push(yaml_rust::Yaml::Hash(linked_hash_map));
}
Err(e) => println!("error parsing header: {:?}", e),
Err(e) => println!("error parsing header: {e:?}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn list_benchmark_file_tasks(benchmark_file: &str, tags: &Tags) {
let mut out_str = String::new();
let mut emitter = YamlEmitter::new(&mut out_str);
emitter.dump(item).unwrap();
println!("{}", out_str);
println!("{out_str}");
}
}

Expand Down