Skip to content

Commit 286cff3

Browse files
author
Chad Greenburg
committed
Update to accept any number of label arguments and fixing unit tests.
Signed-off-by: Chad Greenburg <[email protected]>
1 parent feb2546 commit 286cff3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/macros.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn test_opts_trailing_comma() {
141141
/// let opts = histogram_opts!(name,
142142
/// help,
143143
/// vec![1.0, 2.0],
144-
/// labels!{"key".to_string() => "value".to_string(),});
144+
/// labels!{"key" => "value",});
145145
/// assert_eq!(opts.common_opts.name, name);
146146
/// assert_eq!(opts.common_opts.help, help);
147147
/// assert_eq!(opts.buckets.len(), 2);
@@ -160,9 +160,10 @@ macro_rules! histogram_opts {
160160
hopts.buckets($BUCKETS)
161161
}};
162162

163-
($NAME:expr, $HELP:expr, $BUCKETS:expr, $CONST_LABELS:expr $(,)?) => {{
163+
($NAME:expr, $HELP:expr, $BUCKETS:expr $ ( , $CONST_LABELS:expr ) * $ ( , ) ? ) => {{
164+
use std::collections::HashMap;
165+
164166
let hopts = histogram_opts!($NAME, $HELP, $BUCKETS);
165-
166167
let lbs = HashMap::<String, String>::new();
167168
$(
168169
let mut lbs = lbs;
@@ -193,13 +194,16 @@ fn test_histogram_opts_trailing_comma() {
193194
name,
194195
help,
195196
vec![1.0, 2.0],
196-
labels! {"key".to_string() => "value".to_string(),},
197+
labels! {"key" => "value",},
198+
labels! {"key2" => "value2",},
197199
);
198200
assert_eq!(opts.common_opts.name, name);
199201
assert_eq!(opts.common_opts.help, help);
200202
assert_eq!(opts.buckets.len(), 2);
201203
assert!(opts.common_opts.const_labels.get("key").is_some());
202204
assert_eq!(opts.common_opts.const_labels.get("key").unwrap(), "value");
205+
assert!(opts.common_opts.const_labels.get("key2").is_some());
206+
assert_eq!(opts.common_opts.const_labels.get("key2").unwrap(), "value2");
203207
}
204208

205209
/// Create a [`Counter`] and registers to default registry.

0 commit comments

Comments
 (0)