|
@ -4,7 +4,6 @@ use serde_derive::Deserialize; |
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
pub struct RateLimit {
|
|
|
pub struct RateLimit {
|
|
|
pub(in crate::config) name: String,
|
|
|
|
|
|
pub(in crate::config) number: usize,
|
|
|
pub(in crate::config) number: usize,
|
|
|
pub(in crate::config) period: Duration,
|
|
|
pub(in crate::config) period: Duration,
|
|
|
}
|
|
|
}
|
|
@ -23,32 +22,18 @@ mod tests { |
|
|
#[test]
|
|
|
#[test]
|
|
|
fn ok() {
|
|
|
fn ok() {
|
|
|
let cfg = r#"
|
|
|
let cfg = r#"
|
|
|
name = "test"
|
|
|
|
|
|
number = 20
|
|
|
number = 20
|
|
|
period = "20s"
|
|
|
period = "20s"
|
|
|
"#;
|
|
|
"#;
|
|
|
|
|
|
|
|
|
let rl: RateLimit = load_str(cfg).unwrap();
|
|
|
let rl: RateLimit = load_str(cfg).unwrap();
|
|
|
assert_eq!(rl.name, "test");
|
|
|
|
|
|
assert_eq!(rl.number, 20);
|
|
|
assert_eq!(rl.number, 20);
|
|
|
assert_eq!(rl.period, Duration::from_secs(20));
|
|
|
assert_eq!(rl.period, Duration::from_secs(20));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn missing_name() {
|
|
|
|
|
|
let cfg = r#"
|
|
|
|
|
|
number = 20
|
|
|
|
|
|
period = "20s"
|
|
|
|
|
|
"#;
|
|
|
|
|
|
|
|
|
|
|
|
let res = load_str::<RateLimit>(cfg);
|
|
|
|
|
|
assert!(res.is_err());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn missing_number() {
|
|
|
fn missing_number() {
|
|
|
let cfg = r#"
|
|
|
let cfg = r#"
|
|
|
name = "test"
|
|
|
|
|
|
period = "20s"
|
|
|
period = "20s"
|
|
|
"#;
|
|
|
"#;
|
|
|
|
|
|
|
|
@ -59,7 +44,6 @@ period = "20s" |
|
|
#[test]
|
|
|
#[test]
|
|
|
fn missing_period() {
|
|
|
fn missing_period() {
|
|
|
let cfg = r#"
|
|
|
let cfg = r#"
|
|
|
name = "test"
|
|
|
|
|
|
number = 20
|
|
|
number = 20
|
|
|
"#;
|
|
|
"#;
|
|
|
|
|
|
|
|
|