Skip to content

Commit

Permalink
Fix cache_data.get_from_host_data() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Nov 20, 2023
1 parent 2d34978 commit bbc0dc3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/dns_cache/cache_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ impl CacheData{
let mut cache_data = self.get_cache_data();
if let Some(x) = cache_data.get(&rtype) {
let mut type_hash: HostData = x.clone();
let rr_cache_vec = type_hash.get_from_host_data(domain_name).unwrap();
let rr_cache_vec = type_hash.get_from_host_data(domain_name);
cache_data.insert(rtype, type_hash);
self.set_cache_data(cache_data);
return Some(rr_cache_vec);
return rr_cache_vec;
}
else {
return None;
Expand Down Expand Up @@ -342,10 +342,9 @@ mod cache_data_test{
let rr_cache_vec_2 = cache_data.get_from_cache_data(domain_name.clone(), Rtype::TXT).unwrap();

assert_eq!(rr_cache_vec_2.len(), 1);
let rr_cache_vec_3 = cache_data.get_from_cache_data(DomainName::new(), Rtype::A);

let rr_cache_vec_3 = cache_data.get_from_cache_data(DomainName::new(), Rtype::A).unwrap();

assert!(rr_cache_vec_3.is_empty());
assert!(rr_cache_vec_3.is_none());
}

//remove oldest used test
Expand Down Expand Up @@ -380,12 +379,12 @@ mod cache_data_test{

let a = cache_data.remove_oldest_used();

let vec_rr_cache_txt_expected = cache_data.get_from_cache_data(domain_name_2, Rtype::TXT).unwrap();
let vec_rr_cache_txt_expected = cache_data.get_from_cache_data(domain_name_2, Rtype::TXT);
let vec_rr_cache_a_expected = cache_data.get_from_cache_data(domain_name_1.clone(), Rtype::A).unwrap();

assert_eq!(a,1);
assert_eq!(vec_rr_cache_a_expected.len(), 1);
assert_eq!(vec_rr_cache_txt_expected.len(), 0);
assert!(vec_rr_cache_txt_expected.is_none());
}

//update response time test
Expand Down

0 comments on commit bbc0dc3

Please sign in to comment.