package handlers
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-rest-gw/gen/restapi/operations"
"git.frostfs.info/TrueCloudLab/frostfs-rest-gw/internal/util"
"github.com/stretchr/testify/require"
)
func TestPrepareOffset(t *testing.T) {
for _, tc := range []struct {
err bool
expectedOffset uint64
expectedLength uint64
params operations.GetObjectInfoParams
objSize uint64
}{
{
params: operations.GetObjectInfoParams{
RangeLength: util.NewInteger(1),
RangeOffset: util.NewInteger(0),
},
objSize: 1,
expectedOffset: 0,
expectedLength: 1,
RangeLength: util.NewInteger(3),
RangeOffset: util.NewInteger(1),
objSize: 5,
expectedOffset: 1,
expectedLength: 3,
err: true,
RangeOffset: nil,
RangeLength: nil,
objSize: 0,
} {
t.Run("", func(t *testing.T) {
offset, length, err := prepareOffsetLength(tc.params, tc.objSize)
if tc.err {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.expectedOffset, offset)
require.Equal(t, tc.expectedLength, length)
})