Skip to content

Commit

Permalink
feat: added unit tests for indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Dec 15, 2024
1 parent 1bb8586 commit 27b5bee
Show file tree
Hide file tree
Showing 9 changed files with 787 additions and 217 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ kqueue = "1"

[dev-dependencies]
byte-strings = "0"
clean-path = "0"
criterion = "0"
maplit = "1"
mockall = "0"
Expand Down
14 changes: 8 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::{
settings::{FieldShowOption, Fields, Formatting},
theme::{Element, StylingPush, Theme},
timezone::Tz,
vfs::LocalFileSystem,
IncludeExcludeKeyFilter,
{error::*, QueryNone},
};
Expand Down Expand Up @@ -272,6 +273,7 @@ impl App {
fn sort(&self, inputs: Vec<InputHolder>, output: &mut Output) -> Result<()> {
let mut output = BufWriter::new(output);
let indexer_settings = IndexerSettings::new(
LocalFileSystem,
self.options.buffer_size.try_into()?,
self.options.max_message_size.try_into()?,
&self.options.fields.settings.predefined,
Expand Down Expand Up @@ -499,8 +501,8 @@ impl App {
let reader = scope.spawn(closure!(clone sfi, clone txi, |_| -> Result<()> {
let scanner = Scanner::new(sfi.clone(), &self.options.delimiter);
let mut meta = None;
if let InputReference::File(filename) = &input_ref {
meta = Some(fs::metadata(filename)?);
if let InputReference::File(path) = &input_ref {
meta = Some(fs::metadata(&path.canonical)?);

Check warning on line 505 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L504-L505

Added lines #L504 - L505 were not covered by tests
}
let mut input = Some(input_ref.open()?.tail(self.options.tail)?);

Check warning on line 507 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L507

Added line #L507 was not covered by tests
let is_file = |meta: &Option<fs::Metadata>| meta.as_ref().map(|m|m.is_file()).unwrap_or(false);
Expand All @@ -516,14 +518,14 @@ impl App {
Ok(false)
}
};
if let InputReference::File(filename) = &input_ref {
if let InputReference::File(path) = &input_ref {

Check warning on line 521 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L521

Added line #L521 was not covered by tests
if process(&mut input, is_file(&meta))? {
return Ok(())
}
fsmon::run(vec![filename.clone()], |event| {
fsmon::run(vec![path.canonical.clone()], |event| {

Check warning on line 525 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L525

Added line #L525 was not covered by tests
match event.kind {
EventKind::Modify(_) | EventKind::Create(_) | EventKind::Any | EventKind::Other => {
if let (Some(old_meta), Ok(new_meta)) = (&meta, fs::metadata(&filename)) {
if let (Some(old_meta), Ok(new_meta)) = (&meta, fs::metadata(&path.canonical)) {

Check warning on line 528 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L528

Added line #L528 was not covered by tests
if old_meta.len() > new_meta.len() {
input = None;
}
Expand Down Expand Up @@ -691,7 +693,7 @@ impl App {
fn input_badges<'a, I: IntoIterator<Item = &'a InputReference>>(&self, inputs: I) -> Option<Vec<String>> {
let name = |input: &InputReference| match input {
InputReference::Stdin => "<stdin>".to_owned(),
InputReference::File(path) => path.to_string_lossy().to_string(),
InputReference::File(path) => path.original.to_string_lossy().to_string(),
};

let mut badges = inputs.into_iter().map(|x| name(x).chars().collect_vec()).collect_vec();
Expand Down
Loading

0 comments on commit 27b5bee

Please sign in to comment.