Skip to content

Commit

Permalink
Fix asset resolver with file path
Browse files Browse the repository at this point in the history
  • Loading branch information
2e3s committed Sep 18, 2023
1 parent da9b87c commit 90951c7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion aw-server/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl AssetResolver {

fn resolve(&self, file_path: &str) -> Option<Vec<u8>> {
if let Some(asset_path) = &self.asset_path {
let content = std::fs::read(asset_path);
let content = std::fs::read(asset_path.join(file_path));
if let Ok(data) = content {
return Some(data);
}
Expand Down Expand Up @@ -182,3 +182,23 @@ pub fn build_rocket(server_state: ServerState, config: AWConfig) -> rocket::Rock
}
rocket
}

mod tests {
#[test]
fn test_filesystem_resolver() {
let resolver = super::AssetResolver::new(Some(".".into()));

let content = resolver.resolve("Cargo.toml").unwrap();

assert!(String::from_utf8(content).unwrap().contains("aw-server"));
}

#[test]
fn test_resolver_without_asset() {
let resolver = super::AssetResolver::new(Some(".".into()));

let content = resolver.resolve("Cargo.json");

assert!(content.is_none());
}
}

0 comments on commit 90951c7

Please sign in to comment.