mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 21:00:42 +02:00
This turned out to be a bit more tricky than anticipated: * We want users to see the type this crate exposes, so we need to wrap it all. * We don't want to deal with validating labels here, so we need to delegate. * We need it to be thread-safe, so that we can generate globals. But we also don't want users to deal with locking. * We want a nice-ish API. This now achieves all of this with just one little trick: a sealed trait. That way we can easily extend it to more types, without adding much more code. Note: It might have been nice to use the index operator (`[]`), but that's defined by a trait in Rust and returns a reference to existing data. We thus can't use it and instead provide a simple `get()` method. Differential Revision: https://phabricator.services.mozilla.com/D72805
31 lines
862 B
Rust
31 lines
862 B
Rust
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
mod common;
|
|
use common::*;
|
|
|
|
use glean::metrics::{CommonMetricData, Lifetime, StringMetric};
|
|
|
|
#[test]
|
|
fn sets_string_value() {
|
|
let _lock = lock_test();
|
|
let _t = setup_glean(None);
|
|
let store_names: Vec<String> = vec!["store1".into()];
|
|
|
|
let metric = StringMetric::new(CommonMetricData {
|
|
name: "string_metric".into(),
|
|
category: "telemetry".into(),
|
|
send_in_pings: store_names.clone(),
|
|
disabled: false,
|
|
lifetime: Lifetime::Ping,
|
|
..Default::default()
|
|
});
|
|
|
|
metric.set("test_string_value");
|
|
|
|
assert_eq!(
|
|
"test_string_value",
|
|
metric.test_get_value("store1").unwrap()
|
|
);
|
|
}
|