AccessControl: Team membership migration (#44065)
Co-authored-by: ievaVasiljeva <ieva.vasiljeva@grafana.com> Co-authored-by: Jguer <joao.guerreiro@grafana.com>
This commit is contained in:
co-authored by
ievaVasiljeva
Jguer
parent
dca3dddafd
commit
bc24fdcf8d
@@ -0,0 +1,42 @@
|
||||
package accesscontrol
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBatch(t *testing.T) {
|
||||
type testCase struct {
|
||||
desc string
|
||||
batchSize int
|
||||
count int
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{desc: "empty", batchSize: 1, count: 0},
|
||||
{desc: "1 run of 5", batchSize: 5, count: 5},
|
||||
{desc: "10 runs of 5", batchSize: 5, count: 50},
|
||||
{desc: "unmatching end", batchSize: 10, count: 25},
|
||||
{desc: "batch bigger than count", batchSize: 500, count: 25},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
items := make([]int, tc.count)
|
||||
sum := 0
|
||||
|
||||
got := batch(len(items), tc.batchSize, func(start int, end int) error {
|
||||
chunk := items[start:end]
|
||||
for range chunk {
|
||||
sum += 1
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
require.NoError(t, got)
|
||||
require.Equal(t, tc.count, sum)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user