Skip to content

Commit

Permalink
Skip body scripting (#141)
Browse files Browse the repository at this point in the history
* Removed references to SystemTest (#134)

* Added README instructions for building and link to examples (#136)

* Zip all map (#138)

* add ZipAllMap, and some doc comments and tests

* add doctests to pr.sh

---------

Co-authored-by: Zachery Olson <[email protected]>

* Adds skipBody CLI argument - Skips Request and Response Body in Try Output (#140)

* Cargo version upgrade

* Updated the Guide to include the new available flag options for instructional purposes

* Added the ability to include skipBody argument in TryConfig and modified output to honor new skip flag

* included the new argument in the TmpTryConfig for testing purposes

* change version upgrade back to original as requested

* Removed unnessesary matches as requested

* Changes made to output format as requested

* Format changes as requested

* format changes as requested by Rustfmt in the github checks

* Manually fixed format errors

* Fixed additional fmt failure after updating rust to 1.72

---------

Co-authored-by: Trevor McMaster <[email protected]>

* Fixed fmt and clippy warnings

---------

Co-authored-by: Zachery Olson <[email protected]>
Co-authored-by: Idel <[email protected]>
  • Loading branch information
3 people committed Sep 1, 2023
1 parent 91f82bb commit 3125004
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 86 deletions.
10 changes: 8 additions & 2 deletions guide/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Prints help information
-V, --version Prints version information
-h, --help Prints help information
-V, --version Prints version information
-l, --loggers Enable loggers defined in the config file
-d, --results-directory Directory to store logs (if enabled with --loggers)
-k, --skipBody Skips request and reponse body from output (try command)
```

As signified in the above help output, there are two subcommands `run` and `try`.
Expand Down Expand Up @@ -69,6 +72,7 @@ Options:
endpoint matching the filter is included in the test
-l, --loggers Enable loggers defined in the config file
-d, --results-directory <DIRECTORY> Directory to store logs (if enabled with --loggers)
-k, --skipBody Skips request and reponse body from output (try command)
-h, --help Prints help information
```

Expand All @@ -79,6 +83,8 @@ The `-i`, `--include` parameter allows the filtering of which endpoints are incl
The `-l`, `--loggers` flag specifies that any loggers defined in the config file should be enabled. By default, during a try run, loggers are disabled.

The `-d`, `--results-directory` parameter will store any log files (if the `--loggers` flag is used) in the specified directory. If the directory does not exist it is created.

The `-k`, `--skipBody` parameter ensures that during a Try run, the request and response bodies aren't displayed. This can be particularly useful for debugging requests or responses when the body is not crucial for the debugging process.
<br/><br/>

In both the `run` and `try` subcommands a [config file](./config.md) is required.
Expand Down
17 changes: 9 additions & 8 deletions lib/config/src/configv2/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ impl Endpoint<True> {
.chain(
self.body
.as_ref()
.map_or(BTreeSet::new(), |b| b.get_required_providers())
.into_iter(),
.map_or(BTreeSet::new(), |b| b.get_required_providers()),
)
.chain(self.url.get_required_providers().into_iter())
.chain(self.url.get_required_providers())
// need to figure this out; removing it can mess up the peak load detection,
// but with it, extra values can be taken from providers that are only used
// in declare.
Expand Down Expand Up @@ -220,8 +219,8 @@ impl EndPointBody<True> {
.flat_map(|(_, s)| {
s.headers
.iter()
.flat_map(|(_, h)| h.get_required_providers().into_iter())
.chain(s.body.get_required_providers().into_iter())
.flat_map(|(_, h)| h.get_required_providers())
.chain(s.body.get_required_providers())
})
.collect(),
}
Expand Down Expand Up @@ -422,7 +421,9 @@ mod tests {
}
);

let EndPointBody::<False>::File(FileBody { path: file, .. }) = from_yaml("!file body.txt").unwrap() else {
let EndPointBody::<False>::File(FileBody { path: file, .. }) =
from_yaml("!file body.txt").unwrap()
else {
panic!("was not file variant")
};
assert_eq!(
Expand All @@ -443,8 +444,8 @@ mod tests {
body:
!str some text"#;
let EndPointBody::<False>::Multipart(multipart) = from_yaml(TEST).unwrap() else {
panic!("was not multipart variant")
};
panic!("was not multipart variant")
};
assert_eq!(multipart.len(), 2);
assert_eq!(multipart[0].0, "foo");
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion lib/config/src/configv2/load_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl From<Vec<LoadPatternTemp>> for LoadPattern<False> {
over: Template::new_literal("1s".parse().unwrap()),
}]
.into_iter()
.chain(value.into_iter())
.chain(value)
.tuple_windows()
.map(|(prev, curr)| match curr {
// if `curr` has no `from` defined, take the `to` value of `prev`
Expand Down
8 changes: 5 additions & 3 deletions lib/config/src/configv2/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ mod tests {
fn test_provider_type_response() {
static TEST1: &str = "!response";

let ProviderType::<False>::Response( ResponseProvider {
let ProviderType::<False>::Response(ResponseProvider {
auto_return,
buffer,
unique,
}) = from_yaml(TEST1).unwrap() else {
}) = from_yaml(TEST1).unwrap()
else {
panic!("was not response")
};
assert_eq!(auto_return, None);
Expand All @@ -203,7 +204,8 @@ mod tests {
auto_return,
buffer,
unique,
}) = from_yaml(TEST2).unwrap() else {
}) = from_yaml(TEST2).unwrap()
else {
panic!("was not response")
};
assert_eq!(auto_return, Some(ProviderSend::Block));
Expand Down
26 changes: 19 additions & 7 deletions lib/config/src/configv2/providers/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,18 @@ mod tests {
fn test_file_read_format_csv() {
// defaults
let frf = from_yaml::<FileReadFormat>("!csv").unwrap();
let FileReadFormat::Csv (
CsvParams {comment,
let FileReadFormat::Csv(CsvParams {
comment,
delimiter,
double_quote,
escape,
headers,
terminator,
quote,
}) = frf else { panic!("was not csv") };
}) = frf
else {
panic!("was not csv")
};
assert_eq!(comment, None);
assert_eq!(delimiter, None);
assert_eq!(double_quote, true);
Expand All @@ -210,15 +213,18 @@ mod tests {
"##,
)
.unwrap();
let FileReadFormat::Csv (CsvParams{
let FileReadFormat::Csv(CsvParams {
comment,
delimiter,
double_quote,
escape,
headers,
terminator,
quote,
}) = frf else { panic!("was not csv") };
}) = frf
else {
panic!("was not csv")
};
assert_eq!(comment, Some(CharByte(b'$')));
assert_eq!(delimiter, Some(CharByte(b';')));
assert_eq!(double_quote, false);
Expand All @@ -245,7 +251,10 @@ mod tests {
headers,
terminator,
quote,
}) = frf else { panic!("was not csv") };
}) = frf
else {
panic!("was not csv")
};
assert_eq!(comment, None);
assert_eq!(delimiter, None);
assert_eq!(double_quote, true);
Expand Down Expand Up @@ -351,7 +360,10 @@ format: !csv
headers,
terminator,
quote,
}) = format else { panic!("was not csv") };
}) = format
else {
panic!("was not csv")
};
assert_eq!(comment, None);
assert_eq!(delimiter, None);
assert_eq!(double_quote, true);
Expand Down
12 changes: 7 additions & 5 deletions lib/config/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub fn duration_from_string(dur: &str) -> Option<Duration> {
// unless a value greater then u64::MAX is used
let [n, unit] = (1..=2)
.map(|i| captures.get(i).expect("should have capture group").as_str())
.collect::<Vec<_>>()[..] else {
.collect::<Vec<_>>()[..]
else {
unreachable!()
};
n.parse::<u64>().unwrap()
Expand Down Expand Up @@ -60,10 +61,11 @@ pub(crate) fn get_hits_per(s: &str) -> Option<(f64, Per)> {
let captures = REGEX.captures(s)?;
// None of this should ever panic due to how the regex is formed.
let [n, tag] = (1..=2)
.map(|i| captures.get(i).unwrap().as_str())
.collect::<Vec<_>>()[..] else {
unreachable!()
};
.map(|i| captures.get(i).unwrap().as_str())
.collect::<Vec<_>>()[..]
else {
unreachable!()
};

let n: f64 = n.parse().unwrap();
Some((
Expand Down
Loading

0 comments on commit 3125004

Please sign in to comment.