use std::num::NonZeroU32;
const DEFAULT_MAX_RESULT_SETS: NonZeroU32 = NonZeroU32::new(10).unwrap();
const DEFAULT_MAX_ROWS_PER_RESULT_SET: NonZeroU32 = NonZeroU32::new(1000).unwrap();
#[derive(Debug, Clone, Copy)]
pub struct ProcedureConfig {
pub allow_procedures: bool,
pub require_confirmation: bool,
pub max_result_sets: Option<NonZeroU32>,
pub max_rows_per_result_set: Option<NonZeroU32>,
}
impl Default for ProcedureConfig {
fn default() -> Self {
Self::new()
}
}
impl ProcedureConfig {
#[must_use]
pub const fn new() -> Self {
Self {
allow_procedures: false,
require_confirmation: true,
max_result_sets: Some(DEFAULT_MAX_RESULT_SETS),
max_rows_per_result_set: Some(DEFAULT_MAX_ROWS_PER_RESULT_SET),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_procedure_config_default() {
let config = ProcedureConfig::default();
assert!(!config.allow_procedures);
assert!(config.require_confirmation);
assert_eq!(config.max_result_sets, NonZeroU32::new(10));
assert_eq!(config.max_rows_per_result_set, NonZeroU32::new(1000));
}
#[test]
fn test_procedure_config_new() {
let config = ProcedureConfig::new();
assert!(!config.allow_procedures);
assert!(config.require_confirmation);
assert_eq!(config.max_result_sets, NonZeroU32::new(10));
assert_eq!(config.max_rows_per_result_set, NonZeroU32::new(1000));
}
#[test]
fn test_procedure_config_new_and_default_are_identical() {
let from_new = ProcedureConfig::new();
let from_default = ProcedureConfig::default();
assert_eq!(from_new.allow_procedures, from_default.allow_procedures);
assert_eq!(
from_new.require_confirmation,
from_default.require_confirmation
);
assert_eq!(from_new.max_result_sets, from_default.max_result_sets);
assert_eq!(
from_new.max_rows_per_result_set,
from_default.max_rows_per_result_set
);
}
}