Skip to content

Commit

Permalink
Simplify limiter test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Dec 6, 2023
1 parent b53c71c commit 92efe65
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions sdk/metric/internal/aggregate/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,31 @@ import (
"go.opentelemetry.io/otel/attribute"
)

func TestLimiter(t *testing.T) {
t.Run("Attributes", testAttributes())
}

func testAttributes() func(*testing.T) {
func TestLimiterAttributes(t *testing.T) {
m := map[attribute.Set]struct{}{alice: {}}
return func(t *testing.T) {
t.Run("NoLimit", func(t *testing.T) {
l := newLimiter[struct{}](0)
assert.Equal(t, alice, l.Attributes(alice, m))
assert.Equal(t, bob, l.Attributes(bob, m))
})

t.Run("NotAtLimit/Exists", func(t *testing.T) {
l := newLimiter[struct{}](3)
assert.Equal(t, alice, l.Attributes(alice, m))
})

t.Run("NotAtLimit/DoesNotExist", func(t *testing.T) {
l := newLimiter[struct{}](3)
assert.Equal(t, bob, l.Attributes(bob, m))
})

t.Run("AtLimit/Exists", func(t *testing.T) {
l := newLimiter[struct{}](2)
assert.Equal(t, alice, l.Attributes(alice, m))
})

t.Run("AtLimit/DoesNotExist", func(t *testing.T) {
l := newLimiter[struct{}](2)
assert.Equal(t, overflowSet, l.Attributes(bob, m))
})
}
t.Run("NoLimit", func(t *testing.T) {
l := newLimiter[struct{}](0)
assert.Equal(t, alice, l.Attributes(alice, m))
assert.Equal(t, bob, l.Attributes(bob, m))
})

t.Run("NotAtLimit/Exists", func(t *testing.T) {
l := newLimiter[struct{}](3)
assert.Equal(t, alice, l.Attributes(alice, m))
})

t.Run("NotAtLimit/DoesNotExist", func(t *testing.T) {
l := newLimiter[struct{}](3)
assert.Equal(t, bob, l.Attributes(bob, m))
})

t.Run("AtLimit/Exists", func(t *testing.T) {
l := newLimiter[struct{}](2)
assert.Equal(t, alice, l.Attributes(alice, m))
})

t.Run("AtLimit/DoesNotExist", func(t *testing.T) {
l := newLimiter[struct{}](2)
assert.Equal(t, overflowSet, l.Attributes(bob, m))
})
}

0 comments on commit 92efe65

Please sign in to comment.