Skip to content

Commit 906e2b0

Browse files
authored
Merge branch 'main' into anujnegi/disable-name-check
2 parents 13d6ffd + 6fa9ae2 commit 906e2b0

File tree

1 file changed

+15
-10
lines changed
  • opentelemetry-sdk/src/resource

1 file changed

+15
-10
lines changed

opentelemetry-sdk/src/resource/mod.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl Resource {
9191

9292
/// Create a new `Resource` from key value pairs.
9393
///
94-
/// Values are de-duplicated by key, and the first key-value pair with a non-empty string value
95-
/// will be retained
94+
/// Values are de-duplicated by key, and the last key-value pair will be retained
9695
pub(crate) fn new<T: IntoIterator<Item = KeyValue>>(kvs: T) -> Self {
9796
let mut attrs = HashMap::new();
9897
for kv in kvs {
@@ -331,18 +330,24 @@ mod tests {
331330

332331
use super::*;
333332

334-
#[test]
335-
fn new_resource() {
336-
let args_with_dupe_keys = [KeyValue::new("a", ""), KeyValue::new("a", "final")];
337-
338-
let mut expected_attrs = HashMap::new();
339-
expected_attrs.insert(Key::new("a"), Value::from("final"));
333+
#[rstest]
334+
#[case([KeyValue::new("a", ""), KeyValue::new("a", "final")], [(Key::new("a"), Value::from("final"))])]
335+
#[case([KeyValue::new("a", "final"), KeyValue::new("a", "")], [(Key::new("a"), Value::from(""))])]
336+
fn new_resource(
337+
#[case] given_attributes: [KeyValue; 2],
338+
#[case] expected_attrs: [(Key, Value); 1],
339+
) {
340+
// Arrange
341+
let expected = HashMap::from_iter(expected_attrs.into_iter());
340342

343+
// Act
341344
let resource = Resource::builder_empty()
342-
.with_attributes(args_with_dupe_keys)
345+
.with_attributes(given_attributes)
343346
.build();
344347
let resource_inner = Arc::try_unwrap(resource.inner).expect("Failed to unwrap Arc");
345-
assert_eq!(resource_inner.attrs, expected_attrs);
348+
349+
// Assert
350+
assert_eq!(resource_inner.attrs, expected);
346351
assert_eq!(resource_inner.schema_url, None);
347352
}
348353

0 commit comments

Comments
 (0)