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
use crate::sdk::resource::ResourceDetector;
use crate::sdk::Resource;
use crate::KeyValue;
use std::env::consts::OS;
use std::time::Duration;
#[derive(Debug)]
pub struct OsResourceDetector;
impl ResourceDetector for OsResourceDetector {
fn detect(&self, _timeout: Duration) -> Resource {
Resource::new(vec![KeyValue::new("os.type", OS)])
}
}
#[cfg(target_os = "linux")]
#[cfg(test)]
mod tests {
use crate::sdk::resource::os::OsResourceDetector;
use crate::sdk::resource::ResourceDetector;
use crate::Key;
use std::time::Duration;
#[test]
fn test_os_resource_detector() {
let resource = OsResourceDetector.detect(Duration::from_secs(0));
assert_eq!(
resource
.iter()
.0
.find(|(k, _v)| **k == Key::from_static_str("os.type"))
.map(|(_k, v)| v.to_string()),
Some("linux".to_string())
);
}
}