Skip to content

Commit

Permalink
Add test for pool.Cap
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Sep 16, 2023
1 parent 862e834 commit 242d6fe
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,21 @@ func TestPool_GetClientIDs(t *testing.T) {
assert.Contains(t, ids, "client2.ID")
pool.Clear()
}

func TestPool_Cap(t *testing.T) {
pool := NewPool(context.Background(), 1)
assert.NotNil(t, pool)
assert.NotNil(t, pool.Pool())
assert.Equal(t, 0, pool.Size())
assert.Equal(t, 1, pool.Cap())
err := pool.Put("client1.ID", "client1")
assert.Nil(t, err)
assert.Equal(t, 1, pool.Size())
err = pool.Put("client2.ID", "client2")
assert.NotNil(t, err)
assert.Equal(t, 1, pool.Size())
assert.Equal(t, 1, pool.Cap())
pool.Clear()
assert.Equal(t, 0, pool.Size())
assert.Equal(t, 1, pool.Cap())
}

0 comments on commit 242d6fe

Please sign in to comment.