tiny-counter 0.1.0

Track event counts across time windows with fixed memory and fast queries
Documentation
//! Tests for .usage() method to query limit information

use tiny_counter::{EventStore, TimeUnit};

#[test]
fn usage_returns_limit_info() {
    let store = EventStore::new();

    store.record_count("api_call", 3);

    let usage = store
        .limit()
        .at_most("api_call", 10, TimeUnit::Hours)
        .usage("api_call")
        .unwrap();

    assert_eq!(usage.count, 3);
    assert_eq!(usage.limit, 10);
    assert_eq!(usage.remaining, 7);
}

#[test]
fn usage_at_limit() {
    let store = EventStore::new();

    store.record_count("api_call", 10);

    let usage = store
        .limit()
        .at_most("api_call", 10, TimeUnit::Hours)
        .usage("api_call")
        .unwrap();

    assert_eq!(usage.count, 10);
    assert_eq!(usage.limit, 10);
    assert_eq!(usage.remaining, 0);
}