Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Jan 8, 2025
1 parent 0009a21 commit 5dca00c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
11 changes: 11 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 crates/rari-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ serial_test = { version = "3", features = ["file_locks"] }
rari-types = { workspace = true, features = ["testing"] }
fake = { version = "3", features = ["chrono", "serde_json"] }
rand = "0.8"
assert-json-diff = "2"
84 changes: 44 additions & 40 deletions crates/rari-tools/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,58 +56,62 @@ use serial_test::file_serial;
#[cfg(test)]
#[file_serial(file_fixtures)]
mod test {
use super::*;
use assert_json_diff::assert_json_eq;
use rari_types::locale::Locale;
use serde_json::json;

use super::*;
use crate::tests::fixtures::docs::DocFixtures;

#[test]
fn test_inventory() {
let expected = r#"[
{
"path": "/files/en-us/web/api/index.md",
"frontmatter": {
"title": "API",
"slug": "Web/API"
}
},
{
"path": "/files/en-us/web/api/exampleone/subexampletwo/index.md",
"frontmatter": {
"title": "SubExampleTwo",
"slug": "Web/API/ExampleOne/SubExampleTwo"
}
},
{
"path": "/files/en-us/web/api/exampleone/index.md",
"frontmatter": {
"title": "ExampleOne",
"slug": "Web/API/ExampleOne"
}
},
{
"path": "/files/en-us/web/api/exampleone/subexampleone/index.md",
"frontmatter": {
"title": "SubExampleOne",
"slug": "Web/API/ExampleOne/SubExampleOne"
}
},
{
"path": "/files/en-us/web/index.md",
"frontmatter": {
"title": "Web",
"slug": "Web"
}
}
]"#;
let expected = json!(
[
{
"path": "/files/en-us/web/api/exampleone/index.md",
"frontmatter": {
"title": "ExampleOne",
"slug": "Web/API/ExampleOne"
}
},
{
"path": "/files/en-us/web/api/exampleone/subexampleone/index.md",
"frontmatter": {
"title": "SubExampleOne",
"slug": "Web/API/ExampleOne/SubExampleOne"
}
},
{
"path": "/files/en-us/web/api/exampleone/subexampletwo/index.md",
"frontmatter": {
"title": "SubExampleTwo",
"slug": "Web/API/ExampleOne/SubExampleTwo"
}
},
{
"path": "/files/en-us/web/api/index.md",
"frontmatter": {
"title": "API",
"slug": "Web/API"
}
},
{
"path": "/files/en-us/web/index.md",
"frontmatter": {
"title": "Web",
"slug": "Web"
}
}
]);
let slugs = vec![
"Web/API/ExampleOne".to_string(),
"Web/API/ExampleOne/SubExampleOne".to_string(),
"Web/API/ExampleOne/SubExampleTwo".to_string(),
];
let _docs = DocFixtures::new(&slugs, Locale::EnUs);
let inventory =
let mut inventory =
read_docs_parallel::<InventoryEntry, InventoryEntry>(&[content_root()], None).unwrap();
assert_eq!(expected, serde_json::to_string_pretty(&inventory).unwrap());
inventory.sort_by_key(|entry| entry.path.clone());
assert_json_eq!(expected, serde_json::to_value(&inventory).unwrap());
}
}

0 comments on commit 5dca00c

Please sign in to comment.