65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
|
|
//! `--check` end to end: a configuration on disk through to the resolved
|
||
|
|
//! routing, without a renderer registry or a socket.
|
||
|
|
|
||
|
|
use std::fs;
|
||
|
|
|
||
|
|
const FORMATS: &[&str] = &["gemtext", "html"];
|
||
|
|
|
||
|
|
/// Writes a two-site configuration beside a pair of content roots and returns
|
||
|
|
/// the config path. The config deliberately sits outside both roots.
|
||
|
|
fn fixture(dir: &std::path::Path) -> std::path::PathBuf {
|
||
|
|
let one = dir.join("one");
|
||
|
|
let two = dir.join("two");
|
||
|
|
fs::create_dir_all(&one).unwrap();
|
||
|
|
fs::create_dir_all(&two).unwrap();
|
||
|
|
let text = format!(
|
||
|
|
r#"
|
||
|
|
version = 1
|
||
|
|
|
||
|
|
[site.one]
|
||
|
|
root = "{one}"
|
||
|
|
hosts = ["one.test", "www.one.test"]
|
||
|
|
|
||
|
|
[site.two]
|
||
|
|
root = "{two}"
|
||
|
|
hosts = ["two.test"]
|
||
|
|
|
||
|
|
[listener.web]
|
||
|
|
protocol = "http"
|
||
|
|
bind = "0.0.0.0:8080"
|
||
|
|
formats = ["html"]
|
||
|
|
default_site = "one"
|
||
|
|
|
||
|
|
[listener.feed]
|
||
|
|
protocol = "nex"
|
||
|
|
bind = "0.0.0.0:1900"
|
||
|
|
formats = ["gemtext"]
|
||
|
|
site = "two"
|
||
|
|
"#,
|
||
|
|
one = one.to_str().unwrap(),
|
||
|
|
two = two.to_str().unwrap(),
|
||
|
|
);
|
||
|
|
let path = dir.join("itsybitsy.toml");
|
||
|
|
fs::write(&path, text).unwrap();
|
||
|
|
path
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn checks_a_two_site_configuration() {
|
||
|
|
let dir = tempfile::tempdir().unwrap();
|
||
|
|
let path = fixture(dir.path());
|
||
|
|
itsybitsy::check(&path, FORMATS).unwrap();
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn an_unprovided_format_names_itself_and_the_file() {
|
||
|
|
let dir = tempfile::tempdir().unwrap();
|
||
|
|
let path = fixture(dir.path());
|
||
|
|
// The registry is empty until a format crate lands, which is exactly the
|
||
|
|
// "feature switched off" case an operator hits.
|
||
|
|
let err = itsybitsy::check(&path, &[]).unwrap_err();
|
||
|
|
let rendered = format!("{err:#}");
|
||
|
|
assert!(rendered.contains("itsybitsy.toml"), "{rendered}");
|
||
|
|
assert!(rendered.contains("does not provide"), "{rendered}");
|
||
|
|
}
|