Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Nov 13, 2024
1 parent 97fce68 commit 11ef737
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 28 additions & 8 deletions core/src/layers/mime_guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ impl<A: Access> LayeredAccess for MimeGuessAccessor<A> {
mod tests {
use super::*;
use crate::services::Memory;
use crate::Metadata;
use crate::Operator;
use futures::TryStreamExt;

const DATA: &str = "<html>test</html>";
const CUSTOM: &str = "text/custom";
Expand Down Expand Up @@ -195,10 +197,20 @@ mod tests {
Some(CUSTOM)
);

let entries = op.list_with("").await.unwrap();
assert_eq!(entries[0].metadata().content_type(), Some(HTML));
assert_eq!(entries[1].metadata().content_type(), None);
assert_eq!(entries[2].metadata().content_type(), Some(CUSTOM));
let entries: Vec<Metadata> = op
.lister_with("")
.await
.unwrap()
.and_then(|entry| {
let op = op.clone();
async move { op.stat(entry.path()).await }
})
.try_collect()
.await
.unwrap();
assert_eq!(entries[0].content_type(), Some(HTML));
assert_eq!(entries[1].content_type(), None);
assert_eq!(entries[2].content_type(), Some(CUSTOM));
}

#[test]
Expand All @@ -221,9 +233,17 @@ mod tests {
.unwrap();
assert_eq!(op.stat("test2.html").unwrap().content_type(), Some(CUSTOM));

let entries = op.list_with("").call().unwrap();
assert_eq!(entries[0].metadata().content_type(), Some(HTML));
assert_eq!(entries[1].metadata().content_type(), None);
assert_eq!(entries[2].metadata().content_type(), Some(CUSTOM));
let entries: Vec<Metadata> = op
.lister_with("")
.call()
.unwrap()
.map(|entry| {
let op = op.clone();
op.stat(entry.unwrap().path()).unwrap()
})
.collect();
assert_eq!(entries[0].content_type(), Some(HTML));
assert_eq!(entries[1].content_type(), None);
assert_eq!(entries[2].content_type(), Some(CUSTOM));
}
}
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ mod tests {
#[test]
fn assert_size() {
assert_eq!(40, size_of::<Operator>());
assert_eq!(304, size_of::<Entry>());
assert_eq!(280, size_of::<Metadata>());
assert_eq!(296, size_of::<Entry>());
assert_eq!(272, size_of::<Metadata>());
assert_eq!(1, size_of::<EntryMode>());
assert_eq!(24, size_of::<Scheme>());
}
Expand Down

0 comments on commit 11ef737

Please sign in to comment.