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