Skip to content

Commit

Permalink
test: Add tests for assets with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondk authored and nathanosdev committed Sep 5, 2024
1 parent 4d29cdb commit eefc99e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is another sample asset with special characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bonjour tout le monde!

(This file is used to test assets with special characters)
28 changes: 24 additions & 4 deletions packages/ic-response-verification-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::agent::create_agent;
use anyhow::{anyhow, Result};
use core::panic;
use ic_agent::export::Principal;
use ic_agent::Agent;
use ic_http_certification::{HttpRequest, HttpResponse};
Expand All @@ -9,6 +10,7 @@ use ic_utils::interfaces::http_request::HeaderField;
use ic_utils::interfaces::HttpRequestCanister;
use std::env;
use std::fs;
use std::println;
use std::time::{SystemTime, UNIX_EPOCH};

mod agent;
Expand All @@ -23,12 +25,20 @@ fn get_current_time() -> u128 {
}

fn read_file(file_path: &str) -> Result<Vec<u8>> {
let file = fs::read(format!(
let path = format!(
"packages/ic-response-verification-tests/dfx-project/{}",
file_path
))?;

Ok(file)
);
match fs::read(path.clone()) {
Ok(file) => {
println!("Read file: {}", path);
Ok(file)
}
Err(e) => {
println!("Error reading file: {} from {}", e, path);
Err(e.into())
}
}
}

#[tokio::main]
Expand Down Expand Up @@ -117,6 +127,16 @@ async fn v2_test(canister_id: &str, agent: &Agent) -> Result<()> {
["GET", "/world/", "dist/frontend/index.html"], // load hello/index.html when requesting /hello/ with trailing slash
["GET", "/world/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path
["GET", "/hello/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path
[
"GET",
"/capture-d%E2%80%99%C3%A9cran-2023-10-26-%C3%A0.txt",
"canisters/frontend/assets/capture-d’écran-2023-10-26-à.txt",
], // Load an asset with special characters encoded
[
"GET",
"/another%20sample%20asset.txt",
"canisters/frontend/assets/another sample asset.txt",
], // Load an asset with spaces
];

for [http_method, http_path, file_path] in test_cases.into_iter() {
Expand Down

0 comments on commit eefc99e

Please sign in to comment.