rust_eureka/response/
leaseinfo.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, PartialEq, Deserialize, Serialize)]
4#[serde(rename_all = "camelCase")]
5pub struct LeaseInfo {
6 pub renewal_interval_in_secs: i64,
7 pub duration_in_secs: i64,
8 pub registration_timestamp: i64,
9 pub last_renewal_timestamp: i64,
10 pub eviction_timestamp: i64,
11 pub service_up_timestamp: i64,
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17 use serde_json;
18
19 #[test]
20 fn test_serialize() {
21 let li = build_lease_info();
22 let json = build_lease_info_json();
23 let result = serde_json::to_string(&li).unwrap();
24 assert_eq!(json, result);
25 }
26
27 #[test]
28 fn test_deserialize() {
29 let li = build_lease_info();
30 let json = build_lease_info_json();
31 let result = serde_json::from_str(json.as_ref()).unwrap();
32 assert_eq!(li, result);
33 }
34
35 fn build_lease_info_json() -> String {
36 r#"{
37 "renewalIntervalInSecs": 30,
38 "durationInSecs": 90,
39 "registrationTimestamp": 1503442035871,
40 "lastRenewalTimestamp": 1503442035871,
41 "evictionTimestamp": 0,
42 "serviceUpTimestamp": 1503442035721
43 }"#
44 .to_string()
45 .replace(" ", "")
46 .replace("\n", "")
47 }
48
49 fn build_lease_info() -> LeaseInfo {
50 LeaseInfo {
51 renewal_interval_in_secs: 30,
52 duration_in_secs: 90,
53 registration_timestamp: 1503442035871,
54 last_renewal_timestamp: 1503442035871,
55 eviction_timestamp: 0,
56 service_up_timestamp: 1503442035721,
57 }
58 }
59}