diff --git a/teller-core/src/scan.rs b/teller-core/src/scan.rs index f6d12442..923b8aa4 100644 --- a/teller-core/src/scan.rs +++ b/teller-core/src/scan.rs @@ -85,7 +85,10 @@ pub fn scan_root(root: &str, kvs: &[KV], opts: &Opts) -> Result> { #[cfg(test)] mod tests { - use std::fs; + use std::{ + fs, + path::{Path, PathBuf}, + }; use insta::assert_debug_snapshot; use teller_providers::{ @@ -96,6 +99,19 @@ mod tests { use super::*; use crate::scan; + fn normalize_path_separators(path: &Path) -> PathBuf { + let path_str = path.to_string_lossy().replace('\\', "/"); + PathBuf::from(path_str) + } + fn normalize_matches(ms: &[Match]) -> Vec { + ms.iter() + .map(|m| Match { + path: normalize_path_separators(&m.path), + ..m.clone() + }) + .collect::>() + } + #[test] fn test_position() { assert_eq!(get_visual_position(b"", 4), None); @@ -139,7 +155,7 @@ mod tests { ]; let res = scan_root("fixtures", &kvs[..], &scan::Opts::default()); - assert_debug_snapshot!(res); + assert_debug_snapshot!(normalize_matches(&res.unwrap())); let res = scan_root( "fixtures", @@ -149,7 +165,7 @@ mod tests { include_all: false, }, ); - assert_debug_snapshot!(res); + assert_debug_snapshot!(normalize_matches(&res.unwrap())); fs::write("fixtures/git-ignored-file", "trooper123").expect("cannot write file"); @@ -161,6 +177,6 @@ mod tests { include_all: true, }, ); - assert_debug_snapshot!(res); + assert_debug_snapshot!(normalize_matches(&res.unwrap())); } } diff --git a/teller-core/src/snapshots/teller_core__scan__tests__scan-2.snap b/teller-core/src/snapshots/teller_core__scan__tests__scan-2.snap index 8d102085..627f8937 100644 --- a/teller-core/src/snapshots/teller_core__scan__tests__scan-2.snap +++ b/teller-core/src/snapshots/teller_core__scan__tests__scan-2.snap @@ -1,36 +1,34 @@ --- source: teller-core/src/scan.rs -expression: res +expression: normalize_matches(res.unwrap()) --- -Ok( - [ - Match { - path: "fixtures/config.yml", - position: Some( - ( - 3, - 11, - ), +[ + Match { + path: "fixtures/config.yml", + position: Some( + ( + 3, + 11, ), - offset: 32, - query: KV { - value: "hashicorp", - key: "key1", - from_key: "key1", - path: Some( - PathInfo { - id: "/some/path", - path: "/some/path", - }, - ), - provider: Some( - ProviderInfo { - kind: Inmem, - name: "test", - }, - ), - meta: None, - }, + ), + offset: 32, + query: KV { + value: "hashicorp", + key: "key1", + from_key: "key1", + path: Some( + PathInfo { + id: "/some/path", + path: "/some/path", + }, + ), + provider: Some( + ProviderInfo { + kind: Inmem, + name: "test", + }, + ), + meta: None, }, - ], -) + }, +] diff --git a/teller-core/src/snapshots/teller_core__scan__tests__scan-3.snap b/teller-core/src/snapshots/teller_core__scan__tests__scan-3.snap index 527113d7..fd059e74 100644 --- a/teller-core/src/snapshots/teller_core__scan__tests__scan-3.snap +++ b/teller-core/src/snapshots/teller_core__scan__tests__scan-3.snap @@ -1,64 +1,62 @@ --- source: teller-core/src/scan.rs -expression: res +expression: normalize_matches(res.unwrap()) --- -Ok( - [ - Match { - path: "fixtures/git-ignored-file", - position: Some( - ( - 1, - 1, - ), +[ + Match { + path: "fixtures/git-ignored-file", + position: Some( + ( + 1, + 1, ), - offset: 0, - query: KV { - value: "trooper123", - key: "key1", - from_key: "key1", - path: Some( - PathInfo { - id: "/some/path", - path: "/some/path", - }, - ), - provider: Some( - ProviderInfo { - kind: Inmem, - name: "test", - }, - ), - meta: None, - }, + ), + offset: 0, + query: KV { + value: "trooper123", + key: "key1", + from_key: "key1", + path: Some( + PathInfo { + id: "/some/path", + path: "/some/path", + }, + ), + provider: Some( + ProviderInfo { + kind: Inmem, + name: "test", + }, + ), + meta: None, }, - Match { - path: "fixtures/config.yml", - position: Some( - ( - 3, - 11, - ), + }, + Match { + path: "fixtures/config.yml", + position: Some( + ( + 3, + 11, + ), + ), + offset: 32, + query: KV { + value: "hashicorp", + key: "key1", + from_key: "key1", + path: Some( + PathInfo { + id: "/some/path", + path: "/some/path", + }, + ), + provider: Some( + ProviderInfo { + kind: Inmem, + name: "test", + }, ), - offset: 32, - query: KV { - value: "hashicorp", - key: "key1", - from_key: "key1", - path: Some( - PathInfo { - id: "/some/path", - path: "/some/path", - }, - ), - provider: Some( - ProviderInfo { - kind: Inmem, - name: "test", - }, - ), - meta: None, - }, + meta: None, }, - ], -) + }, +] diff --git a/teller-core/src/snapshots/teller_core__scan__tests__scan.snap b/teller-core/src/snapshots/teller_core__scan__tests__scan.snap index 8d102085..627f8937 100644 --- a/teller-core/src/snapshots/teller_core__scan__tests__scan.snap +++ b/teller-core/src/snapshots/teller_core__scan__tests__scan.snap @@ -1,36 +1,34 @@ --- source: teller-core/src/scan.rs -expression: res +expression: normalize_matches(res.unwrap()) --- -Ok( - [ - Match { - path: "fixtures/config.yml", - position: Some( - ( - 3, - 11, - ), +[ + Match { + path: "fixtures/config.yml", + position: Some( + ( + 3, + 11, ), - offset: 32, - query: KV { - value: "hashicorp", - key: "key1", - from_key: "key1", - path: Some( - PathInfo { - id: "/some/path", - path: "/some/path", - }, - ), - provider: Some( - ProviderInfo { - kind: Inmem, - name: "test", - }, - ), - meta: None, - }, + ), + offset: 32, + query: KV { + value: "hashicorp", + key: "key1", + from_key: "key1", + path: Some( + PathInfo { + id: "/some/path", + path: "/some/path", + }, + ), + provider: Some( + ProviderInfo { + kind: Inmem, + name: "test", + }, + ), + meta: None, }, - ], -) + }, +]