#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("\"{0}\" unknown")]
pub struct InvalidHookEvent(String);
impl InvalidHookEvent {
pub(crate) fn new(value: &str) -> Self {
Self(value.to_owned())
}
#[must_use]
pub fn value(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("\"{0}\" unknown")]
pub struct InvalidMatchValue(String);
impl InvalidMatchValue {
pub(crate) fn new(value: &str) -> Self {
Self(value.to_owned())
}
#[must_use]
pub fn value(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum InvalidPolicy {
#[error("\"{text}\" is not allowed for pack hooks")]
NotAllowed {
text: String,
},
#[error(
"\"pure\" is not supported in api 0 (airsl has no require under pure, airsstack/airsl#12)"
)]
PureUnsupported,
#[error("\"{text}\" (expected confined)")]
Unknown {
text: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn invalid_hook_event_display_quotes_the_value() {
let error = InvalidHookEvent::new("tool.pre");
assert_eq!(error.to_string(), "\"tool.pre\" unknown");
assert_eq!(error.value(), "tool.pre");
}
#[test]
fn invalid_match_value_display_quotes_the_value() {
let error = InvalidMatchValue::new("bash");
assert_eq!(error.to_string(), "\"bash\" unknown");
assert_eq!(error.value(), "bash");
}
#[test]
fn invalid_policy_displays_each_message() {
let cases = [
(
InvalidPolicy::NotAllowed {
text: "trusted".to_owned(),
},
"\"trusted\" is not allowed for pack hooks",
),
(
InvalidPolicy::PureUnsupported,
"\"pure\" is not supported in api 0 (airsl has no require under pure, airsstack/airsl#12)",
),
(
InvalidPolicy::Unknown {
text: "foo".to_owned(),
},
"\"foo\" (expected confined)",
),
];
for (error, message) in cases {
assert_eq!(error.to_string(), message);
}
}
}