Skip to content

Commit

Permalink
align tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed May 12, 2024
1 parent 38b9c94 commit 1dabcf3
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 123 deletions.
24 changes: 20 additions & 4 deletions teller-core/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ pub fn scan_root(root: &str, kvs: &[KV], opts: &Opts) -> Result<Vec<Match>> {

#[cfg(test)]
mod tests {
use std::fs;
use std::{
fs,
path::{Path, PathBuf},
};

use insta::assert_debug_snapshot;
use teller_providers::{
Expand All @@ -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<Match> {
ms.iter()
.map(|m| Match {
path: normalize_path_separators(&m.path),
..m.clone()
})
.collect::<Vec<_>>()
}

#[test]
fn test_position() {
assert_eq!(get_visual_position(b"", 4), None);
Expand Down Expand Up @@ -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",
Expand All @@ -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");

Expand All @@ -161,6 +177,6 @@ mod tests {
include_all: true,
},
);
assert_debug_snapshot!(res);
assert_debug_snapshot!(normalize_matches(&res.unwrap()));
}
}
60 changes: 29 additions & 31 deletions teller-core/src/snapshots/teller_core__scan__tests__scan-2.snap
Original file line number Diff line number Diff line change
@@ -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,
},
],
)
},
]
112 changes: 55 additions & 57 deletions teller-core/src/snapshots/teller_core__scan__tests__scan-3.snap
Original file line number Diff line number Diff line change
@@ -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,
},
],
)
},
]
60 changes: 29 additions & 31 deletions teller-core/src/snapshots/teller_core__scan__tests__scan.snap
Original file line number Diff line number Diff line change
@@ -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,
},
],
)
},
]

0 comments on commit 1dabcf3

Please sign in to comment.