Skip to content

Commit 32cc65b

Browse files
committed
normalize paths in testing routing
1 parent 9bb20ad commit 32cc65b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/webserver/routing.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ mod tests {
440440

441441
async fn do_route(path: &str, config: StoreConfig, prefix: Option<&str>) -> RoutingAction {
442442
let store = match config {
443-
Default => Store::default(),
443+
Default => Store::with_default_contents(),
444444
Empty => Store::empty(),
445445
File(file) => Store::new(file),
446446
};
@@ -496,22 +496,26 @@ mod tests {
496496
vec![Self::INDEX.to_string(), Self::NOT_FOUND.to_string()]
497497
}
498498

499+
fn with_default_contents() -> Self {
500+
Self {
501+
contents: Self::default_contents(),
502+
}
503+
}
504+
499505
fn empty() -> Self {
500506
Self { contents: vec![] }
501507
}
502-
}
503508

504-
impl StdDefault for Store {
505-
fn default() -> Self {
506-
Self {
507-
contents: Self::default_contents(),
508-
}
509+
fn contains(&self, path: &str) -> bool {
510+
let normalized_path = path.replace('\\', "/");
511+
dbg!(&normalized_path, &self.contents);
512+
self.contents.contains(&normalized_path)
509513
}
510514
}
511515

512516
impl FileStore for Store {
513517
async fn contains(&self, path: &Path) -> anyhow::Result<bool> {
514-
Ok(self.contents.contains(&path.to_string_lossy().to_string()))
518+
Ok(self.contains(path.to_string_lossy().to_string().as_str()))
515519
}
516520
}
517521

tests/index.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,7 @@ async fn test_routing_with_db_fs_and_prefix() {
728728
sqlx::any::AnyKind::Mssql => "INSERT INTO sqlpage_files(path, contents) VALUES ('on_db.sql', CONVERT(VARBINARY(MAX), 'select ''text'' as component, ''Hi from db !'' AS contents;'))",
729729
_ => "INSERT INTO sqlpage_files(path, contents) VALUES ('on_db.sql', 'select ''text'' as component, ''Hi from db !'' AS contents;')"
730730
};
731-
state
732-
.db
733-
.connection
734-
.execute(insert_sql)
735-
.await
736-
.unwrap();
731+
state.db.connection.execute(insert_sql).await.unwrap();
737732

738733
let app_data = actix_web::web::Data::new(state);
739734

0 commit comments

Comments
 (0)