rust_eureka/response/
amazonmetadata.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, PartialEq, Serialize, Deserialize)]
4#[serde(rename_all = "kebab-case")]
5pub struct AmazonMetaData {
6 pub ami_launch_index: String,
7 pub local_hostname: String,
8 pub availability_zone: String,
9 pub instance_id: String,
10 pub public_ipv4: String,
11 pub public_hostname: String,
12 pub ami_manifest_path: String,
13 pub local_ipv4: String,
14 pub hostname: String,
15 pub ami_id: String,
16 pub instance_type: String,
17}
18
19#[cfg(test)]
20pub mod tests {
21 use super::*;
22 use serde_json;
23
24 #[test]
25 fn test_serialize_amazon_meta_data() {
26 let md = AmazonMetaData {
27 ami_launch_index: "001a".to_string(),
28 local_hostname: "localhost0".to_string(),
29 availability_zone: "US_East1a".to_string(),
30 instance_id: "instance1a".to_string(),
31 public_ipv4: "32.23.21.212".to_string(),
32 public_hostname: "foo.coma".to_string(),
33 ami_manifest_path: "/dev/nulla".to_string(),
34 local_ipv4: "127.0.0.12".to_string(),
35 hostname: "privatefoo.coma".to_string(),
36 ami_id: "ami0023".to_string(),
37 instance_type: "c4xlarged".to_string(),
38 };
39 let json = sample_meta_data();
40
41 let result = serde_json::to_string(&md).unwrap();
42 assert_eq!(json, result);
43 }
44
45 #[test]
46 fn test_deserialize_amazon_meta_data() {
47 let md = AmazonMetaData {
48 ami_launch_index: "001a".to_string(),
49 local_hostname: "localhost0".to_string(),
50 availability_zone: "US_East1a".to_string(),
51 instance_id: "instance1a".to_string(),
52 public_ipv4: "32.23.21.212".to_string(),
53 public_hostname: "foo.coma".to_string(),
54 ami_manifest_path: "/dev/nulla".to_string(),
55 local_ipv4: "127.0.0.12".to_string(),
56 hostname: "privatefoo.coma".to_string(),
57 ami_id: "ami0023".to_string(),
58 instance_type: "c4xlarged".to_string(),
59 };
60 let json = sample_meta_data();
61 let result = serde_json::from_str(&json).unwrap();
62 assert_eq!(md, result);
63 }
64
65 pub fn sample_meta_data() -> String {
66 r#"{ "ami-launch-index": "001a",
67 "local-hostname": "localhost0",
68 "availability-zone": "US_East1a",
69 "instance-id": "instance1a",
70 "public-ipv4": "32.23.21.212",
71 "public-hostname": "foo.coma",
72 "ami-manifest-path": "/dev/nulla",
73 "local-ipv4": "127.0.0.12",
74 "hostname": "privatefoo.coma",
75 "ami-id": "ami0023",
76 "instance-type": "c4xlarged" }"#
77 .to_string()
78 .replace(" ", "")
79 .replace("\n", "")
80 }
81}