This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
frostfs-rest-gw/handlers/objects_test.go
Denis Kirillov 8d83320120 [#79] Fix panic on get empty object
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-10-20 11:01:22 +03:00

77 lines
1.6 KiB
Go

package handlers
import (
"testing"
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
"github.com/nspcc-dev/neofs-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,
},
{
params: operations.GetObjectInfoParams{
RangeLength: util.NewInteger(3),
RangeOffset: util.NewInteger(1),
},
objSize: 5,
expectedOffset: 1,
expectedLength: 3,
},
{
objSize: 1,
expectedOffset: 0,
expectedLength: 1,
},
{
err: true,
params: operations.GetObjectInfoParams{
RangeLength: util.NewInteger(1),
RangeOffset: nil,
},
},
{
err: true,
params: operations.GetObjectInfoParams{
RangeLength: nil,
RangeOffset: util.NewInteger(1),
},
},
{
err: true,
params: operations.GetObjectInfoParams{
RangeLength: util.NewInteger(1),
RangeOffset: util.NewInteger(0),
},
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)
})
}
}