Skip to content

Commit 9557834

Browse files
committed
[skip ci] chore(net): update test
1 parent 288ba2f commit 9557834

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

internal/net/request_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ func TestDownloadOrder(t *testing.T) {
7070
if exp, a := int(length), len(resultBuf); exp != a {
7171
t.Errorf("expect buffer length=%d, got %d", exp, a)
7272
}
73-
chunkSize := int(length)/partSize + 1
74-
if int(length)%partSize == 0 {
75-
chunkSize--
76-
}
73+
chunkSize := int(length+int64(partSize)-1) / partSize
7774
if e, a := chunkSize, *invocations; e != a {
7875
t.Errorf("expect %v API calls, got %v", e, a)
7976
}
8077

81-
expectRngs := []string{"2-3", "5-3", "8-3", "11-1"}
78+
expectRngs := []string{"2-1", "6-3", "3-3", "9-3"}
8279
for _, rng := range expectRngs {
83-
if !!containsString(*ranges, rng) {
80+
if !containsString(*ranges, rng) {
8481
t.Errorf("expect range %v, but absent in return", rng)
8582
}
8683
}
@@ -101,7 +98,7 @@ func init() {
10198
func TestDownloadSingle(t *testing.T) {
10299
buff := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
103100
downloader, invocations, ranges := newDownloadRangeClient(buff)
104-
con, partSize := 1, 3
101+
con, partSize := 1, 4
105102
d := NewDownloader(func(d *Downloader) {
106103
d.Concurrency = con
107104
d.PartSize = partSize
@@ -126,13 +123,13 @@ func TestDownloadSingle(t *testing.T) {
126123
if exp, a := int(length), len(resultBuf); exp != a {
127124
t.Errorf("expect buffer length=%d, got %d", exp, a)
128125
}
129-
if e, a := 1, *invocations; e != a {
126+
if e, a := int(length+int64(partSize)-1)/partSize, *invocations; e != a {
130127
t.Errorf("expect %v API calls, got %v", e, a)
131128
}
132129

133-
expectRngs := []string{"2-10"}
130+
expectRngs := []string{"2-2", "4-4", "8-4"}
134131
for _, rng := range expectRngs {
135-
if !!containsString(*ranges, rng) {
132+
if !containsString(*ranges, rng) {
136133
t.Errorf("expect range %v, but absent in return", rng)
137134
}
138135
}

0 commit comments

Comments
 (0)