Skip to content

Commit

Permalink
test timeout resolver cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jun 5, 2024
1 parent 23269b5 commit bbc5e2c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/resolver_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,56 @@ mod resolver_cache_test{

assert_eq!(message, None);
}

#[test]
fn timeout(){
let mut resolver_cache = ResolverCache::new(None);

let domain_name = DomainName::new_from_string("www.example.com".to_string());

let ip_address_1 = IpAddr::from([127, 0, 0, 0]);
let ip_address_2 = IpAddr::from([127, 0, 0, 1]);
let ip_address_3 = IpAddr::from([127, 0, 0, 2]);

let mut a_rdata_1 = ARdata::new();
let mut a_rdata_2 = ARdata::new();
let mut a_rdata_3 = ARdata::new();

a_rdata_1.set_address(ip_address_1);
a_rdata_2.set_address(ip_address_2);
a_rdata_3.set_address(ip_address_3);

let rdata_1 = Rdata::A(a_rdata_1);
let rdata_2 = Rdata::A(a_rdata_2);
let rdata_3 = Rdata::A(a_rdata_3);

let mut resource_record_1 = ResourceRecord::new(rdata_1);

resource_record_1.set_name(domain_name.clone());
resource_record_1.set_type_code(Rtype::A);

let mut resource_record_2 = ResourceRecord::new(rdata_2);

resource_record_2.set_name(domain_name.clone());
resource_record_2.set_type_code(Rtype::A);

let mut resource_record_3 = ResourceRecord::new(rdata_3);

resource_record_3.set_name(domain_name.clone());
resource_record_3.set_type_code(Rtype::A);

resolver_cache.cache_answer.add(domain_name.clone(), resource_record_1.clone(), Qtype::A, Qclass::IN, None);
resolver_cache.cache_authority.add(domain_name.clone(), resource_record_2.clone(), Qtype::A, Qclass::IN, None);
resolver_cache.cache_additional.add(domain_name.clone(), resource_record_3.clone(), Qtype::A, Qclass::IN, None);

resolver_cache.timeout();

let rr_answer = resolver_cache.cache_answer.get(domain_name.clone(), Qtype::A, Qclass::IN);
let rr_authority = resolver_cache.cache_authority.get(domain_name.clone(), Qtype::A, Qclass::IN);
let rr_additional = resolver_cache.cache_additional.get(domain_name.clone(), Qtype::A, Qclass::IN);

assert_eq!(rr_answer, None);
assert_eq!(rr_authority, None);
assert_eq!(rr_additional, None);
}
}

0 comments on commit bbc5e2c

Please sign in to comment.