2018-07-27 18:31:27 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package ranger
|
|
|
|
|
|
|
|
import (
|
2018-07-30 20:25:18 +01:00
|
|
|
"context"
|
2018-07-27 18:31:27 +01:00
|
|
|
"testing"
|
2018-07-30 20:25:18 +01:00
|
|
|
|
2018-07-27 18:31:27 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRange(t *testing.T) {
|
|
|
|
for _, tt := range []struct {
|
|
|
|
name string
|
|
|
|
offset int64
|
|
|
|
length int64
|
|
|
|
size int64
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Negative offset",
|
|
|
|
offset: -2,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: "Negative length",
|
|
|
|
offset: 2,
|
|
|
|
length: -1,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
rr := readerAtRanger{size: tt.size}
|
|
|
|
closer, err := rr.Range(context.Background(), tt.offset, tt.length)
|
|
|
|
assert.Nil(t, closer)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClose(t *testing.T) {
|
2018-07-30 20:25:18 +01:00
|
|
|
rr := readerAtReader{length: 0}
|
2018-07-27 18:31:27 +01:00
|
|
|
assert.Nil(t, rr.Close())
|
2018-07-30 20:25:18 +01:00
|
|
|
}
|