use std::fs;
use std::path::Path;
#[test]
fn every_plugin_toml_parses_as_plugin_file_shape() {
let plugins_dir = Path::new("plugins");
let entries = fs::read_dir(plugins_dir).expect("plugins/ must exist");
let mut checked = 0;
for entry in entries {
let entry = entry.unwrap();
let path = entry.path();
let name = path
.file_name()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_string();
if !name.ends_with(".toml") || name == "_index.toml" {
continue;
}
let text = fs::read_to_string(&path).unwrap();
let _: pathlint::catalog::PluginFileShape = toml::from_str(&text)
.unwrap_or_else(|e| panic!("plugin {name} fails to parse as PluginFileShape: {e}"));
checked += 1;
}
assert!(
checked >= 5,
"fewer than 5 plugin files were exercised; cwd is probably wrong"
);
}
#[test]
fn no_plugin_toml_contains_catalog_version_key() {
let plugins_dir = Path::new("plugins");
for entry in fs::read_dir(plugins_dir).expect("plugins/ must exist") {
let entry = entry.unwrap();
let path = entry.path();
let name = path
.file_name()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_string();
if !name.ends_with(".toml") || name == "_index.toml" {
continue;
}
let body = fs::read_to_string(&path).unwrap();
assert!(
!body.contains("catalog_version"),
"plugin {name} declares catalog_version; that key belongs to _index.toml only"
);
}
}
#[test]
fn index_toml_lists_existing_plugin_files() {
let index_text = fs::read_to_string("plugins/_index.toml").unwrap();
let parsed: toml::Value = toml::from_str(&index_text).unwrap();
let plugins = parsed
.get("plugins")
.and_then(|v| v.as_array())
.expect("_index.toml must declare a `plugins` array");
for name in plugins {
let name = name.as_str().expect("plugin entries are strings");
let path = format!("plugins/{name}.toml");
assert!(
Path::new(&path).is_file(),
"_index.toml lists `{name}` but {path} does not exist"
);
}
}