2022-06-21 18:01:00 +03:00
|
|
|
mod fixtures;
|
|
|
|
mod utils;
|
|
|
|
|
2022-09-05 05:30:45 +03:00
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use assert_fs::fixture::TempDir;
|
|
|
|
use fixtures::{port, server, tmpdir, wait_for_port, Error, TestServer, DIR_ASSETS};
|
2022-06-21 18:01:00 +03:00
|
|
|
use rstest::rstest;
|
2022-09-05 05:30:45 +03:00
|
|
|
use std::process::{Command, Stdio};
|
2022-06-21 18:01:00 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn assets(server: TestServer) -> Result<(), Error> {
|
|
|
|
let ver = env!("CARGO_PKG_VERSION");
|
|
|
|
let resp = reqwest::blocking::get(server.url())?;
|
2024-02-06 12:23:18 +03:00
|
|
|
let index_js = format!("/__dufs_v{ver}_/index.js");
|
|
|
|
let index_css = format!("/__dufs_v{ver}_/index.css");
|
|
|
|
let favicon_ico = format!("/__dufs_v{ver}_/favicon.ico");
|
2022-06-21 18:01:00 +03:00
|
|
|
let text = resp.text()?;
|
2024-02-06 12:23:18 +03:00
|
|
|
println!("{text}");
|
2023-02-20 06:05:53 +03:00
|
|
|
assert!(text.contains(&format!(r#"href="{index_css}""#)));
|
|
|
|
assert!(text.contains(&format!(r#"href="{favicon_ico}""#)));
|
|
|
|
assert!(text.contains(&format!(r#"src="{index_js}""#)));
|
2022-06-21 18:01:00 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn asset_js(server: TestServer) -> Result<(), Error> {
|
|
|
|
let url = format!(
|
2024-02-06 12:23:18 +03:00
|
|
|
"{}__dufs_v{}_/index.js",
|
2022-06-21 18:01:00 +03:00
|
|
|
server.url(),
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
);
|
|
|
|
let resp = reqwest::blocking::get(url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
assert_eq!(
|
|
|
|
resp.headers().get("content-type").unwrap(),
|
2023-11-15 14:44:44 +03:00
|
|
|
"application/javascript; charset=UTF-8"
|
2022-06-21 18:01:00 +03:00
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn asset_css(server: TestServer) -> Result<(), Error> {
|
|
|
|
let url = format!(
|
2024-02-06 12:23:18 +03:00
|
|
|
"{}__dufs_v{}_/index.css",
|
2022-06-21 18:01:00 +03:00
|
|
|
server.url(),
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
);
|
|
|
|
let resp = reqwest::blocking::get(url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
2023-11-15 14:44:44 +03:00
|
|
|
assert_eq!(
|
|
|
|
resp.headers().get("content-type").unwrap(),
|
|
|
|
"text/css; charset=UTF-8"
|
|
|
|
);
|
2022-06-21 18:01:00 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn asset_ico(server: TestServer) -> Result<(), Error> {
|
|
|
|
let url = format!(
|
2024-02-06 12:23:18 +03:00
|
|
|
"{}__dufs_v{}_/favicon.ico",
|
2022-06-21 18:01:00 +03:00
|
|
|
server.url(),
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
);
|
|
|
|
let resp = reqwest::blocking::get(url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
assert_eq!(resp.headers().get("content-type").unwrap(), "image/x-icon");
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-06-25 03:15:16 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn assets_with_prefix(#[with(&["--path-prefix", "xyz"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let ver = env!("CARGO_PKG_VERSION");
|
|
|
|
let resp = reqwest::blocking::get(format!("{}xyz/", server.url()))?;
|
2024-02-06 12:23:18 +03:00
|
|
|
let index_js = format!("/xyz/__dufs_v{ver}_/index.js");
|
|
|
|
let index_css = format!("/xyz/__dufs_v{ver}_/index.css");
|
|
|
|
let favicon_ico = format!("/xyz/__dufs_v{ver}_/favicon.ico");
|
2022-06-25 03:15:16 +03:00
|
|
|
let text = resp.text()?;
|
2023-02-20 06:05:53 +03:00
|
|
|
assert!(text.contains(&format!(r#"href="{index_css}""#)));
|
|
|
|
assert!(text.contains(&format!(r#"href="{favicon_ico}""#)));
|
|
|
|
assert!(text.contains(&format!(r#"src="{index_js}""#)));
|
2022-06-25 03:15:16 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn asset_js_with_prefix(
|
|
|
|
#[with(&["--path-prefix", "xyz"])] server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let url = format!(
|
2024-02-06 12:23:18 +03:00
|
|
|
"{}xyz/__dufs_v{}_/index.js",
|
2022-06-25 03:15:16 +03:00
|
|
|
server.url(),
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
);
|
|
|
|
let resp = reqwest::blocking::get(url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
assert_eq!(
|
|
|
|
resp.headers().get("content-type").unwrap(),
|
2023-11-15 14:44:44 +03:00
|
|
|
"application/javascript; charset=UTF-8"
|
2022-06-25 03:15:16 +03:00
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-09-05 05:30:45 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn assets_override(tmpdir: TempDir, port: u16) -> Result<(), Error> {
|
|
|
|
let mut child = Command::cargo_bin("dufs")?
|
|
|
|
.arg(tmpdir.path())
|
|
|
|
.arg("-p")
|
|
|
|
.arg(port.to_string())
|
|
|
|
.arg("--assets")
|
|
|
|
.arg(tmpdir.join(DIR_ASSETS))
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
wait_for_port(port);
|
|
|
|
|
2023-02-20 06:05:53 +03:00
|
|
|
let url = format!("http://localhost:{port}");
|
2022-09-05 05:30:45 +03:00
|
|
|
let resp = reqwest::blocking::get(&url)?;
|
|
|
|
assert!(resp.text()?.starts_with(&format!(
|
2024-02-06 12:23:18 +03:00
|
|
|
"/__dufs_v{}_/index.js;DATA",
|
2022-09-05 05:30:45 +03:00
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
)));
|
|
|
|
let resp = reqwest::blocking::get(&url)?;
|
|
|
|
assert_resp_paths!(resp);
|
|
|
|
|
|
|
|
child.kill()?;
|
|
|
|
Ok(())
|
|
|
|
}
|