stix_matcher/
observation.rs1use stix_model::StixObject;
4
5#[derive(Debug, Clone)]
8pub struct Observation {
9 pub objects: Vec<StixObject>,
11 pub first_observed: Option<String>,
13 pub last_observed: Option<String>,
15 pub number_observed: u64,
17}
18
19impl Observation {
20 pub fn new(objects: Vec<StixObject>) -> Self {
22 Observation {
23 objects,
24 first_observed: None,
25 last_observed: None,
26 number_observed: 1,
27 }
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34 use stix_model::StixObject;
35
36 fn sco(json: serde_json::Value) -> StixObject {
37 StixObject::from_json(json).unwrap()
38 }
39
40 #[test]
41 fn new_defaults_number_observed_to_one() {
42 let o = Observation::new(vec![sco(serde_json::json!({
43 "type": "ipv4-addr", "id": "ipv4-addr--1", "value": "1.2.3.4"
44 }))]);
45 assert_eq!(o.objects.len(), 1);
46 assert_eq!(o.number_observed, 1);
47 assert!(o.first_observed.is_none());
48 }
49}