gary_core/tests/
mod.rs

1#[cfg(test)]
2pub mod tests {
3
4    use crate::config::*;
5    use crate::data::*;
6    use crate::yaml::*;
7
8    use std::collections::HashMap;
9
10    #[test]
11    fn test_merge() {
12        let contents = include_str!("./test_config.yaml");
13        let input: serde_yaml::Value = serde_yaml::from_str(&contents).unwrap();
14        let mut result = serde_yaml::to_value(&ClusterConfig::new_default()).unwrap();
15        merge(&mut result, &input);
16        let mut other_result = ClusterConfig::new_default();
17
18        other_result.gossip_config.interval = 6;
19        other_result.gossip_config.port = 9876;
20        other_result.deployment_config.port = 991122;
21        other_result.node_info.node_name = "Bobby".to_string();
22
23        let a: ClusterConfig = serde_yaml::from_value(result).unwrap();
24        assert_eq!(a, other_result);
25        assert_ne!(a, ClusterConfig::new_default());
26    }
27
28    #[test]
29    fn read_deployment_test() {
30        let contents = include_str!("./test_deploy.yaml");
31        /*fs::read_to_string("./tests/test_deploy.yaml")
32            .expect("something went wrong reading the file");
33        */
34        let mut deployment = Deployment {
35            version: "apps/v1".to_string(),
36            kind: "Deployment".to_string(),
37            metadata: MetaData {
38                name: Some("nginx-deployment".to_string()),
39                labels: HashMap::new(),
40            },
41            spec: DeploymentSpec {
42                replicas: 3,
43                template: DeploymentTemplate {
44                    metadata: MetaData {
45                        name: None,
46                        labels: HashMap::new(),
47                    },
48                    spec: Spec {
49                        containers: Vec::new(),
50                    },
51                },
52            },
53        };
54
55        deployment
56            .metadata
57            .labels
58            .insert("app".to_string(), "nginx".to_string());
59        deployment
60            .spec
61            .template
62            .metadata
63            .labels
64            .insert("app".to_string(), "nginx".to_string());
65        let container = Container {
66            name: "nginx".to_string(),
67            image: "nginx:1.7.9".to_string(),
68            ports: vec![Ports { container_port: 80 }],
69        };
70        deployment
71            .spec
72            .template
73            .spec
74            .containers
75            .insert(0, container);
76
77        let file_deploy: Deployment = serde_yaml::from_str(&contents).expect("not to fail");
78        assert_eq!(deployment, file_deploy);
79    }
80}