Skip to main content

rust_eureka/response/
application.rs

1use super::Instance;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, PartialEq, Serialize, Deserialize)]
5pub struct Application {
6    pub name: String,
7    // server returns instance as an array
8    pub instance: Vec<Instance>,
9}
10
11#[cfg(test)]
12mod tests {
13    use super::super::instance::tests::{build_test_instance, build_test_instance_json};
14    use super::*;
15    use serde_json;
16
17    #[test]
18    fn test_instance_serialization() {
19        let json = build_register_json();
20        let instance = build_test_instance();
21        let name = "test_name";
22        let app = Application {
23            name: name.to_owned(),
24            instance: vec![instance],
25        };
26        let result = serde_json::to_string(&app).unwrap();
27
28        //                let combined = json.chars().zip(result.chars());
29        //                for (a, b) in combined {
30        //                    print!("{}", b);
31        //                    assert_eq!(a, b);
32        //                }
33        assert_eq!(json, result);
34    }
35
36    #[test]
37    fn test_instance_deserialization() {
38        let json = build_register_json();
39        let instance = build_test_instance();
40        let name = "test_name";
41        let app = Application {
42            name: name.to_owned(),
43            instance: vec![instance],
44        };
45        let result = serde_json::from_str(&json).unwrap();
46        assert_eq!(app, result);
47    }
48
49    fn build_register_json() -> String {
50        format!(
51            "{{\"name\":\"test_name\",\"instance\":[{}]}}",
52            build_test_instance_json()
53        )
54    }
55}