use rainier_support::setting_enum;
setting_enum! {
pub enum AppEnv: "application environment" {
#[default]
Production = "production",
Staging = "staging",
Local = "local",
Testing = "testing",
}
}
impl AppEnv {
pub fn is_developing(&self) -> bool {
matches!(self, Self::Local | Self::Testing)
}
pub fn is_serving_users(&self) -> bool {
matches!(self, Self::Production)
}
pub fn may_leak_details(&self) -> bool {
self.is_developing()
}
}
#[cfg(test)]
mod tests {
use super::*;
use rainier_support::Setting;
#[test]
fn an_unset_environment_is_production() {
assert_eq!(AppEnv::default(), AppEnv::Production);
assert!(!AppEnv::default().is_developing());
}
#[test]
fn staging_is_production_shaped_but_has_no_real_users() {
assert!(!AppEnv::Staging.is_developing());
assert!(!AppEnv::Staging.is_serving_users());
assert!(AppEnv::Production.is_serving_users());
}
#[test]
fn only_the_development_environments_may_leak_details() {
for env in AppEnv::ALL {
assert_eq!(env.may_leak_details(), env.is_developing(), "{env}");
}
}
}