Skip to content

Commit

Permalink
Test glob path provider
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Sichert <[email protected]>
  • Loading branch information
pablosichert committed Jan 8, 2021
1 parent 5fcc1d0 commit 18cdd01
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/file-source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ dashmap = "4.0.0"
quickcheck = "0.9"
rand = "0.7"
tempfile = "3.1.0"

[[test]]
name = "glob"
Empty file.
Empty file.
58 changes: 58 additions & 0 deletions lib/file-source/tests/glob.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use file_source::paths_provider::{glob::Glob, PathsProvider};

#[test]
fn test_glob_include_plain() -> Result<(), Box<dyn std::error::Error>> {
let include_patterns = ["tests/files/foo.log".to_owned()];
let exclude_patterns = [];
let glob = Glob::new(&include_patterns, &exclude_patterns)?;

let paths = glob.paths()?;

assert_eq!(
paths,
["./tests/files/foo.log"]
.iter()
.map(std::path::PathBuf::from)
.collect::<Vec<_>>()
);

Ok(())
}

#[test]
fn test_glob_include_curly_braces() -> Result<(), Box<dyn std::error::Error>> {
let include_patterns = ["tests/files/{foo,bar}.log".to_owned()];
let exclude_patterns = [];
let glob = Glob::new(&include_patterns, &exclude_patterns)?;

let paths = glob.paths()?;

assert_eq!(
paths,
["./tests/files/foo.log", "./tests/files/bar.log"]
.iter()
.map(std::path::PathBuf::from)
.collect::<Vec<_>>()
);

Ok(())
}

#[test]
fn test_glob_include_curly_braces_exclude_star() -> Result<(), Box<dyn std::error::Error>> {
let include_patterns = ["tests/files/{foo,bar}.log".to_owned()];
let exclude_patterns = ["**/foo.log".to_owned()];
let glob = Glob::new(&include_patterns, &exclude_patterns)?;

let paths = glob.paths()?;

assert_eq!(
paths,
["./tests/files/bar.log"]
.iter()
.map(std::path::PathBuf::from)
.collect::<Vec<_>>()
);

Ok(())
}

0 comments on commit 18cdd01

Please sign in to comment.