Skip to content

Commit

Permalink
feat(test): use tracing instead of fern for agent mock
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Oct 28, 2022
1 parent 2b951f9 commit 9c2e599
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/filter/filter_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl FilterBodyAction {

match self.do_filter(data.clone()) {
Ok(filtered) => filtered,
Err(_) => {
Err(err) => {
log::error!("error while filtering: {}", err);
self.in_error = true;

data
Expand All @@ -85,7 +86,8 @@ impl FilterBodyAction {

match self.do_end() {
Ok(end) => end,
Err(_) => {
Err(err) => {
log::error!("error while ending filtering: {}", err);
self.in_error = true;

Vec::new()
Expand Down
2 changes: 2 additions & 0 deletions src/filter/gzip_filter_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl GzDecodeFilterBody {
let mut decoder = GzDecoder::new(Cursor::new(Vec::new()));
std::mem::swap(&mut self.decoder, &mut decoder);

decoder.try_finish()?;
Ok(decoder.finish()?.into_inner())
}
}
Expand All @@ -56,6 +57,7 @@ impl GzEncodeFilterBody {
let mut encoder = GzEncoder::new(Cursor::new(Vec::new()), flate2::Compression::default());
std::mem::swap(&mut self.encoder, &mut encoder);

encoder.try_finish()?;
Ok(encoder.finish()?.into_inner())
}
}
16 changes: 8 additions & 8 deletions src/filter/html_body_action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ impl HtmlBodyVisitor {
}

pub fn evaluate(data: &str, expression: &str) -> bool {
let document = scraper::Html::parse_fragment(data);
let selector_result = scraper::Selector::parse(expression);

if selector_result.is_err() {
error!("Cannot parse selector {}: {:?}", expression, selector_result.err().unwrap());
let selector = match scraper::Selector::parse(expression) {
Ok(selector) => selector,
Err(err) => {
log::error!("cannot parse selector {}: {:?}", expression, err);

return false;
}
return false;
}
};

let selector = selector_result.unwrap();
let document = scraper::Html::parse_fragment(data);
let mut select = document.select(&selector);

select.next().is_some()
Expand Down

0 comments on commit 9c2e599

Please sign in to comment.