Some checks failed
DCO action / DCO (pull_request) Successful in 3m8s
Vulncheck / Vulncheck (pull_request) Successful in 3m16s
Build / Build Components (1.20) (pull_request) Successful in 4m13s
Build / Build Components (1.21) (pull_request) Successful in 4m16s
Tests and linters / Staticcheck (pull_request) Successful in 5m11s
Tests and linters / Lint (pull_request) Successful in 5m58s
Tests and linters / Tests with -race (pull_request) Failing after 6m3s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m29s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m38s
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
33 lines
849 B
Go
33 lines
849 B
Go
package writecachebitcask
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDispatchRecoveredIndices(t *testing.T) {
|
|
max := uint32(math.MaxUint32)
|
|
tests := []struct {
|
|
indices []uint32
|
|
wantOrder []uint32
|
|
wantIndex uint32
|
|
}{
|
|
{[]uint32{0}, []uint32{0}, 1},
|
|
{[]uint32{42}, []uint32{42}, 43},
|
|
{[]uint32{5, 6, 7, 8}, []uint32{5, 6, 7, 8}, 9},
|
|
{[]uint32{max - 2, max - 1, max}, []uint32{max - 2, max - 1, max}, 0},
|
|
{[]uint32{0, 1, 2, max - 2, max - 1, max}, []uint32{max - 2, max - 1, max, 0, 1, 2}, 3},
|
|
{[]uint32{0, max}, []uint32{max, 0}, 1},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
var gotOrder []uint32
|
|
gotIndex := dispatchRecoveredLogIndices(tc.indices, func(i uint32) {
|
|
gotOrder = append(gotOrder, i)
|
|
})
|
|
require.Equal(t, tc.wantOrder, gotOrder)
|
|
require.Equal(t, tc.wantIndex, gotIndex)
|
|
}
|
|
}
|