Skip to content

Commit 5201543

Browse files
committed
added test
1 parent cc7cd67 commit 5201543

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

opentelemetry/src/baggage.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,4 +566,22 @@ mod tests {
566566
assert!(b.to_string().contains("bar=2;yellow"));
567567
assert!(b.to_string().contains("foo=1;red;state=on"));
568568
}
569+
570+
#[test]
571+
fn replace_existing_key() {
572+
let half_minus2: StringValue = (0..MAX_LEN_OF_ALL_PAIRS / 2 - 2)
573+
.map(|_| 'x')
574+
.collect::<String>()
575+
.into();
576+
577+
let mut b = Baggage::default();
578+
b.insert("a", half_minus2.clone()); // +1 for key
579+
b.insert("b", half_minus2); // +1 for key
580+
b.insert("c", StringValue::from(".")); // total of 2 bytes
581+
assert!(b.get("a").is_some());
582+
assert!(b.get("b").is_some());
583+
assert!(b.get("c").is_some());
584+
assert!(b.insert("c", StringValue::from("..")).is_none()); // exceeds MAX_LEN_OF_ALL_PAIRS
585+
assert_eq!(b.insert("c", StringValue::from("!")).unwrap(), ".".into()); // replaces existing
586+
}
569587
}

0 commit comments

Comments
 (0)