mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-17 11:07:18 +02:00
databroker: add options for maximum capacity (#2095)
* databroker: add options * implement redis * add trace for enforce options
This commit is contained in:
parent
b3216ae854
commit
636b3d6846
14 changed files with 1085 additions and 419 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
|
@ -150,3 +151,32 @@ func TestStream(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, eg.Wait())
|
||||
}
|
||||
|
||||
func TestCapacity(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
backend := New()
|
||||
defer func() { _ = backend.Close() }()
|
||||
|
||||
err := backend.SetOptions(ctx, "EXAMPLE", &databroker.Options{
|
||||
Capacity: proto.Uint64(3),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
err = backend.Put(ctx, &databroker.Record{
|
||||
Type: "EXAMPLE",
|
||||
Id: fmt.Sprint(i),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
records, _, err := backend.GetAll(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, records, 3)
|
||||
|
||||
var ids []string
|
||||
for _, r := range records {
|
||||
ids = append(ids, r.GetId())
|
||||
}
|
||||
assert.Equal(t, []string{"7", "8", "9"}, ids, "should contain recent records")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue