Skip to content

Commit

Permalink
adding tests for CachedValue size
Browse files Browse the repository at this point in the history
  • Loading branch information
yaleman committed Mar 18, 2024
1 parent 7ad56a8 commit c9cdb0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ pub struct SearchCacheKey {

#[derive(Debug, Clone)]
pub struct CachedValue {
valid_until: Instant,
entries: Vec<(LdapSearchResultEntry, Vec<LdapControl>)>,
result: LdapResult,
ctrl: Vec<LdapControl>,
pub valid_until: Instant,
pub entries: Vec<(LdapSearchResultEntry, Vec<LdapControl>)>,
pub result: LdapResult,
pub ctrl: Vec<LdapControl>,
}

impl CachedValue {
fn size(&self) -> usize {
pub fn size(&self) -> usize {
std::mem::size_of::<Self>() + self.entries.iter().map(|(e, _)| e.size()).sum::<usize>()
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// use ldap_proxy::proxy::BasicLdapClient;

use ldap3_proto::proto::LdapResult;
use ldap_proxy::proxy::CachedValue;
use ldap_proxy::Config;
use std::time::{Duration, Instant};

#[test]
fn hello_world() {
Expand All @@ -16,3 +19,19 @@ fn test_config_load() {

assert_eq!(config.ldap_ca.to_str(), Some("/etc/ldap-proxy/ldap-ca.pem"));
}

#[test]
fn test_cachedvalue() {
let cv = CachedValue {
valid_until: Instant::now() + Duration::from_secs(60),
entries: Vec::with_capacity(5),
result: LdapResult {
code: ldap3_proto::LdapResultCode::Busy,
matcheddn: "dn=doo".to_string(),
message: "ohno".to_string(),
referral: Vec::with_capacity(5),
},
ctrl: Vec::with_capacity(5),
};
assert_eq!(cv.size(), 144);
}

0 comments on commit c9cdb0c

Please sign in to comment.