You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-19 21:45:50 +02:00
attribute: test map equivalence with duplicate keys (#8473)
Add coverage documenting the map equivalence behavior for duplicated keys. This follows the prior-art semantics of `attribute.Set`. Side note: there is already a `duplicate keys keep stable order` test case in `TestAsMap`. However, I think that adding these test cases is a good coverage addition.
This commit is contained in:
@@ -199,6 +199,20 @@ func TestEquivalence(t *testing.T) {
|
||||
attribute.Bool("b", true),
|
||||
),
|
||||
},
|
||||
{
|
||||
// Map equivalence sorts entries stably by key;
|
||||
// when duplicate keys exist, the relative order of same-key entries must match.
|
||||
attribute.Map(
|
||||
"Map",
|
||||
attribute.Bool("a", true),
|
||||
attribute.Map("a", attribute.String("nested", "value")),
|
||||
),
|
||||
attribute.Map(
|
||||
"Map",
|
||||
attribute.Bool("a", true),
|
||||
attribute.Map("a", attribute.String("nested", "value")),
|
||||
),
|
||||
},
|
||||
{
|
||||
attribute.KeyValue{Key: "Empty"},
|
||||
attribute.KeyValue{Key: "Empty"},
|
||||
@@ -310,6 +324,20 @@ func TestNotEquivalence(t *testing.T) {
|
||||
attribute.Map("Map", attribute.String("key", "value")),
|
||||
attribute.Map("Map", attribute.String("other", "value")),
|
||||
},
|
||||
{
|
||||
// With duplicate keys, changing the relative order of same-key entries changes map equivalence
|
||||
// (stable key sort preserves duplicates' order).
|
||||
attribute.Map(
|
||||
"Map",
|
||||
attribute.Bool("a", true),
|
||||
attribute.Map("a", attribute.String("nested", "value")),
|
||||
),
|
||||
attribute.Map(
|
||||
"Map",
|
||||
attribute.Map("a", attribute.String("nested", "value")),
|
||||
attribute.Bool("a", true),
|
||||
),
|
||||
},
|
||||
{
|
||||
attribute.KeyValue{Key: "Empty"},
|
||||
attribute.String("Empty", ""),
|
||||
|
||||
Reference in New Issue
Block a user