omaha_client/metrics/
stub.rs

1// Copyright 2019 The Fuchsia Authors
2//
3// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6// This file may not be copied, modified, or distributed except according to
7// those terms.
8
9use crate::metrics::{Metrics, MetricsReporter};
10use anyhow::Error;
11use tracing::info;
12
13/// A stub implementation of MetricsReporter which only log metrics.
14#[derive(Debug)]
15pub struct StubMetricsReporter;
16
17impl MetricsReporter for StubMetricsReporter {
18    fn report_metrics(&mut self, metrics: Metrics) -> Result<(), Error> {
19        info!("Received request to report metrics: {:?}", metrics);
20        Ok(())
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use std::time::Duration;
28
29    #[test]
30    fn test_stub_metrics_reporter() {
31        let mut stub = StubMetricsReporter;
32        let result = stub.report_metrics(Metrics::UpdateCheckResponseTime {
33            response_time: Duration::from_secs(2),
34            successful: true,
35        });
36        assert!(result.is_ok(), "{result:?}");
37    }
38}