-
Notifications
You must be signed in to change notification settings - Fork 3
/
object_test.go
100 lines (98 loc) · 3.01 KB
/
object_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package pump
import "testing"
func TestObject_IsCompletedBy(t *testing.T) {
type fields struct {
ID string
Size int64
}
type args struct {
finishedChunks []Chunk
}
tests := []struct {
name string
fields fields
args args
wantFinished bool
}{
{
name: "simple complete",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 500, Offset: 500, Object: Object{ID: "o1", Size: 1000}},
{Size: 500, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: true,
},
{
name: "simple incomplete",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 450, Offset: 500, Object: Object{ID: "o1", Size: 1000}},
{Size: 500, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: false,
},
{
name: "overlapping complete",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 200, Offset: 100, Object: Object{ID: "o1", Size: 1000}},
{Size: 950, Offset: 50, Object: Object{ID: "o1", Size: 1000}},
{Size: 200, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: true,
},
{
name: "overlapping incomplete",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 200, Offset: 100, Object: Object{ID: "o1", Size: 1000}},
{Size: 850, Offset: 50, Object: Object{ID: "o1", Size: 1000}},
{Size: 200, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: false,
},
{
name: "overlapping complete with duplicated offsets",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 200, Offset: 100, Object: Object{ID: "o1", Size: 1000}},
{Size: 300, Offset: 50, Object: Object{ID: "o1", Size: 1000}},
{Size: 900, Offset: 50, Object: Object{ID: "o1", Size: 1000}},
{Size: 500, Offset: 50, Object: Object{ID: "o1", Size: 1000}},
{Size: 200, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
{Size: 100, Offset: 900, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: true,
},
{
name: "trailing edge incomplete",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 499, Offset: 500, Object: Object{ID: "o1", Size: 1000}},
{Size: 500, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: false,
},
{
name: "ignore chunks from different objects",
fields: fields{ID: "o1", Size: 1000},
args: args{finishedChunks: []Chunk{
{Size: 500, Offset: 500, Object: Object{ID: "o2", Size: 1000}},
{Size: 500, Offset: 0, Object: Object{ID: "o1", Size: 1000}},
}},
wantFinished: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := Object{
ID: tt.fields.ID,
Size: tt.fields.Size,
}
if gotFinished := o.isCompletedBy(tt.args.finishedChunks); gotFinished != tt.wantFinished {
t.Errorf("Object.isCompletedBy() = %v, want %v", gotFinished, tt.wantFinished)
}
})
}
}