forked from johannesboyne/gofakes3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
range_test.go
51 lines (46 loc) · 1.47 KB
/
range_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gofakes3
import (
"fmt"
"testing"
)
func TestRangeRequest(t *testing.T) {
for idx, tc := range []struct {
inst, inend int64
rev bool
sz int64
outst, outln int64
fail bool
}{
{inst: 0, inend: RangeNoEnd, sz: 5, outst: 0, outln: 5},
{inst: 0, inend: 5, sz: 10, outst: 0, outln: 6},
{inst: 0, inend: 0, sz: 4, outst: 0, outln: 1},
{inst: 1, inend: 5, sz: 10, outst: 1, outln: 5},
{inst: 1, inend: 5, sz: 3, outst: 1, outln: 2},
{inst: 5, inend: 7, sz: 6, outst: 5, outln: 1},
{rev: true, inend: 10, sz: 10, outst: 0, outln: 10},
{rev: true, inend: 5, sz: 10, outst: 5, outln: 5},
{fail: true, inst: 0, inend: 0, sz: 0},
{fail: true, inst: 1, inend: 1, sz: 1},
{fail: true, inst: 10, inend: 15, sz: 10},
{fail: true, inst: 40, inend: 50, sz: 11},
{fail: true, rev: true, inend: 20, sz: 10},
{fail: true, rev: true, inend: 11, sz: 10},
{fail: true, rev: true, inend: 0, sz: 10}, // zero suffix-length is not satisfiable
} {
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
orr := ObjectRangeRequest{Start: tc.inst, End: tc.inend, FromEnd: tc.rev}
rng, err := orr.Range(tc.sz)
if tc.fail != (err != nil) {
t.Fatal("failure expected:", tc.fail, "found:", err)
}
if !tc.fail {
if rng.Start != tc.outst {
t.Fatal("unexpected start:", rng.Start, "expected:", tc.outst)
}
if rng.Length != tc.outln {
t.Fatal("unexpected length:", rng.Length, "expected:", tc.outln)
}
}
})
}
}