Skip to content

Commit

Permalink
fix: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 10, 2025
1 parent 56d0149 commit f5331b1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ unused-features:
unused-features analyze

test:
cargo test --features=full
cargo test --workspace --features=full

cov:
cargo llvm-cov --html --open
cargo llvm-cov --workspace --html --open

release:
cargo build --release
Expand Down
1 change: 1 addition & 0 deletions pingap-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ full = ["opentelemetry"]

[dev-dependencies]
pretty_assertions = "1.4.0"
tempfile = "3.16.0"
9 changes: 6 additions & 3 deletions pingap-core/src/http_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ mod tests {
use http::StatusCode;
use pretty_assertions::assert_eq;
use serde::Serialize;
use std::io::Write;
use tempfile::NamedTempFile;
use tokio::fs;

#[test]
fn test_new_cache_control_header() {
assert_eq!(
Expand Down Expand Up @@ -408,8 +409,10 @@ mod tests {
}
#[tokio::test]
async fn test_http_chunk_response() {
let file = "../../error.html";
let mut f = fs::OpenOptions::new().read(true).open(file).await.unwrap();
let file = include_bytes!("../../error.html");
let mut f = NamedTempFile::new().unwrap();
f.write_all(file).unwrap();
let mut f = fs::OpenOptions::new().read(true).open(f).await.unwrap();
let mut resp = HttpChunkResponse::new(&mut f);
resp.max_age = Some(3600);
resp.cache_private = Some(false);
Expand Down
9 changes: 9 additions & 0 deletions pingap-plugin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<h1>Pingap</h1>
</body>
</html>
11 changes: 6 additions & 5 deletions pingap-plugin/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl TryFrom<&PluginConf> for Directory {
download: get_bool_conf(value, "download"),
headers: Some(headers),
};
println!("directory params: {:?}", params.path);
if ![PluginStep::Request, PluginStep::ProxyUpstream]
.contains(&params.plugin_step)
{
Expand Down Expand Up @@ -597,7 +598,7 @@ path = "./"
chunk_size = 1024
max_age = "1h"
private = true
index = "/pingap/index.html"
index = "/index.html"
autoindex = true
download = true
"###,
Expand All @@ -608,11 +609,11 @@ download = true
assert_eq!(4096, dir.chunk_size.unwrap_or_default());
assert_eq!(3600, dir.max_age.unwrap_or_default());
assert_eq!(true, dir.cache_private.unwrap_or_default());
assert_eq!("/pingap/index.html", dir.index);
assert_eq!("/index.html", dir.index);

let headers = ["Accept-Encoding: gzip"].join("\r\n");
let input_header =
format!("GET /error.html?size=1 HTTP/1.1\r\n{headers}\r\n\r\n");
format!("GET /index.html?size=1 HTTP/1.1\r\n{headers}\r\n\r\n");
let mock_io = Builder::new().read(input_header.as_bytes()).build();
let mut session = Session::new_h1(Box::new(mock_io));
session.read_request().await.unwrap();
Expand All @@ -633,7 +634,7 @@ download = true
format!("{:?}", headers[0])
);
assert_eq!(
r#"("content-disposition", "attachment; filename=\"error.html\"")"#,
r#"("content-disposition", "attachment; filename=\"index.html\"")"#,
format!("{:?}", headers[2])
);
assert_eq!(true, !resp.body.is_empty());
Expand Down Expand Up @@ -667,7 +668,7 @@ download = true

#[tokio::test]
async fn test_get_data() {
let file = Path::new("./error.html").to_path_buf();
let file = Path::new("./index.html").to_path_buf();
let (meta, _) = get_data(&file).await.unwrap();

assert_ne!(0, meta.size());
Expand Down
2 changes: 1 addition & 1 deletion pingap-util/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use regex::Regex;
///
/// # Example
/// ```
/// use pingap::pingap_util::RegexCapture;
/// use pingap_util::RegexCapture;
/// let re = RegexCapture::new(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})").unwrap();
/// let (matched, captures) = re.captures("2024-03-14");
/// assert_eq!(true, matched);
Expand Down

0 comments on commit f5331b1

Please sign in to comment.