Skip to content

Commit d81dea9

Browse files
committed
fix!: Ser/De of HardwareMetric to be accurate
1 parent 18f0f4c commit d81dea9

1 file changed

Lines changed: 84 additions & 68 deletions

File tree

src/status.rs

Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct HardwareMetric {
4545
pub model: Option<String>,
4646
#[cfg_attr(feature = "serde", serde(rename = "type"))]
4747
pub hw_type: String,
48-
pub metrics: Vec<Value>,
48+
pub metrics: Vec<ValueMetric>,
4949
}
5050

5151
#[cfg_attr(
@@ -58,9 +58,9 @@ pub struct HardwareMetric {
5858
pub struct ValueMetric {
5959
#[cfg_attr(feature = "serde", serde(rename = "type"))]
6060
pub type_string: String,
61+
#[cfg_attr(feature = "serde", serde(flatten))]
6162
pub value: Value,
6263
pub unit: String,
63-
pub value_type: String,
6464
}
6565

6666
#[cfg_attr(
@@ -86,72 +86,88 @@ mod tests {
8686
#[cfg(feature = "serde")]
8787
fn deserialize() {
8888
let json_value = r#"{
89-
"site":
90-
{
91-
"taskId":78939,
92-
"taskRequestUri":"https://test-api.atlasground.com/api/requests/78939",
93-
"name":"AIB1",
94-
"configuration":"AIB1-000A",
95-
"siteUri":"https://test-api.atlasground.com/api/sites/27",
96-
"configUri":"https://test-api.atlasground.com/api/configurations/35",
97-
"collected":1648733340.076000000,
98-
"hardwareMetrics":
99-
[
100-
{
101-
"name":"aib1_000a.modem.amergint_technologies.0",
102-
"mfg":"Amergint Technologies",
103-
"model":"satTRAC",
104-
"type":"MODEM",
105-
"metrics":
106-
[
107-
{
108-
"type":"site.hardware.modem.status",
109-
"value":true,
110-
"unit":"bool",
111-
"valueType":"bool"
112-
}
113-
]
114-
},
115-
{
116-
"name":"aib1_000a.digitizer.real_time_logic.0",
117-
"mfg":"Real Time Logic",
118-
"model":"1.7.4",
119-
"type":"DIGITIZER",
120-
"metrics":
121-
[
122-
{
123-
"type":"site.hardware.digitizer.status",
124-
"value":true,
125-
"unit":"bool",
126-
"valueType":"bool"
127-
}
128-
]
129-
},
130-
{
131-
"name":"Site Server",
132-
"mfg":"ATLAS",
133-
"model":"1.6.1",
134-
"type":"SUM",
135-
"metrics":
136-
[
137-
{
138-
"type":"site.hardware.status",
139-
"value":true,
140-
"unit":"bool",
141-
"valueType":"bool"
142-
},
143-
{
144-
"type":"site.hardware.pass.timing",
145-
"value":3467,
146-
"unit":"s",
147-
"valueType":"long"
148-
}
149-
]
150-
}
151-
]
152-
}
153-
}"#;
89+
"site": {
90+
"taskId": 1,
91+
"taskRequestUri": "https://test-api.atlasground.com/api/requests/1",
92+
"name": "MySite",
93+
"configuration": "MySite-000A",
94+
"siteUri": "https://test-api.atlasground.com/api/sites/1",
95+
"configUri": "https://test-api.atlasground.com/api/configurations/1",
96+
"collected": 1648733340.076,
97+
"hardwareMetrics": [
98+
{
99+
"name": "test-hardware",
100+
"mfg": "Tech",
101+
"model": "1.x.x",
102+
"type": "MODEM",
103+
"metrics": [
104+
{
105+
"type": "site.hardware.modem.status",
106+
"value": true,
107+
"unit": "bool",
108+
"valueType": "bool"
109+
}
110+
]
111+
},
112+
{
113+
"name": "test-hardware",
114+
"mfg": "Tech",
115+
"model": "1.x.x",
116+
"type": "DIGITIZER",
117+
"metrics": [
118+
{
119+
"type": "site.hardware.digitizer.status",
120+
"value": true,
121+
"unit": "bool",
122+
"valueType": "bool"
123+
}
124+
]
125+
},
126+
{
127+
"name": "Site Server",
128+
"mfg": "ATLAS",
129+
"model": "1.x.x",
130+
"type": "SUM",
131+
"metrics": [
132+
{
133+
"type": "site.hardware.status",
134+
"value": true,
135+
"unit": "bool",
136+
"valueType": "bool"
137+
},
138+
{
139+
"type": "site.hardware.pass.timing",
140+
"value": 3467,
141+
"unit": "s",
142+
"valueType": "long"
143+
}
144+
]
145+
}
146+
]
147+
}
148+
}"#;
154149

155-
let _ser: PassMetric = serde_json::from_slice(json_value.as_bytes()).unwrap();
150+
let ser: PassMetric = serde_json::from_slice(json_value.as_bytes()).unwrap();
151+
let first = &ser.site.hardware_metrics[0].metrics[0];
152+
assert_eq!(first.type_string.as_str(), "site.hardware.modem.status");
153+
assert_eq!(&first.value, &Value::Bool(true));
154+
let second = &ser.site.hardware_metrics[1].metrics[0];
155+
assert_eq!(
156+
second.type_string.as_str(),
157+
"site.hardware.digitizer.status"
158+
);
159+
assert_eq!(&second.value, &Value::Bool(true));
160+
let second = &ser.site.hardware_metrics[1].metrics[0];
161+
assert_eq!(
162+
second.type_string.as_str(),
163+
"site.hardware.digitizer.status"
164+
);
165+
assert_eq!(&second.value, &Value::Bool(true));
166+
let third = &ser.site.hardware_metrics[2].metrics[0];
167+
assert_eq!(third.type_string.as_str(), "site.hardware.status");
168+
assert_eq!(&third.value, &Value::Bool(true));
169+
let fourth = &ser.site.hardware_metrics[2].metrics[1];
170+
assert_eq!(fourth.type_string.as_str(), "site.hardware.pass.timing");
171+
assert_eq!(&fourth.value, &Value::Long(3467));
156172
}
157173
}

0 commit comments

Comments
 (0)