forked from oam-dev/rudr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstigator_test.rs
111 lines (104 loc) · 3.66 KB
/
instigator_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::instigator::*;
use crate::schematic::configuration::ComponentConfiguration;
use std::collections::BTreeMap;
#[test]
fn test_config_owner_reference() {
let name = "configuration".to_string();
let uid = "87707f2d-9ddc-11e9-b1c3-4ec16ac9a10f".to_string();
config_owner_reference(name.clone(), Some(uid.clone()))
.and_then(|owner| {
assert_eq!(owner.name, name);
assert_eq!(owner.uid, uid);
Ok(owner)
})
.expect("expected owner reference");
}
#[test]
fn test_record_ann() {
let records = None;
let ann = get_record_annotation(records).expect("get_record_annotation from none");
assert_eq!(ann.len(), 0);
let mut one: RecordAnnotation = BTreeMap::new();
let cr = ComponentRecord {
version: "123".to_string(),
config: ComponentConfiguration {
component_name: "n123".to_string(),
instance_name: "inst123".to_string(),
parameter_values: None,
traits: None,
application_scopes: None,
},
};
let cr2 = ComponentRecord {
version: "321".to_string(),
config: ComponentConfiguration {
component_name: "n321".to_string(),
instance_name: "inst321".to_string(),
parameter_values: None,
traits: None,
application_scopes: None,
},
};
one.insert("comp1".to_string(), cr.clone());
one.insert("comp2".to_string(), cr2.clone());
let json_str = &serde_json::to_string(&one).expect("record annotation json value");
let records = Some(json_str);
let ann = get_record_annotation(records).expect("get_record_annotation from json");
assert_eq!(2, ann.len());
let crgot = ann.get("comp1").expect("comp1 ComponentRecord");
let crgot2 = ann.get("comp2").expect("comp2 ComponentRecord");
assert_eq!(crgot, &cr);
assert_eq!(crgot2, &cr2);
}
#[test]
fn test_check_diff() {
let new_record = ComponentRecord {
version: "123".to_string(),
config: ComponentConfiguration {
component_name: "test".to_string(),
instance_name: "test_inst".to_string(),
parameter_values: None,
traits: None,
application_scopes: None,
},
};
let old_record = ComponentRecord {
version: "123".to_string(),
config: ComponentConfiguration {
component_name: "test".to_string(),
instance_name: "test_inst".to_string(),
parameter_values: None,
traits: None,
application_scopes: None,
},
};
assert_eq!(check_diff(None, &new_record), true);
assert_eq!(check_diff(Some(old_record.clone()), &new_record), false);
let new_record2 = ComponentRecord {
version: "1234".to_string(),
config: ComponentConfiguration {
component_name: "test".to_string(),
instance_name: "test_inst".to_string(),
parameter_values: None,
traits: None,
application_scopes: None,
},
};
assert_eq!(check_diff(Some(new_record2), &old_record), true);
let new_record3 = ComponentRecord {
version: "1234".to_string(),
config: ComponentConfiguration {
component_name: "test".to_string(),
instance_name: "test_inst".to_string(),
parameter_values: Some(vec![]),
traits: None,
application_scopes: None,
},
};
assert_eq!(check_diff(Some(new_record3), &old_record), true);
}
#[test]
fn test_combine_name() {
let name = combine_name("component-a".to_string(), "instance-b".to_string());
assert_eq!("component-a-instance-b", name.as_str())
}