-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimiter_reader_test.go
55 lines (48 loc) · 946 Bytes
/
limiter_reader_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
// Copyright (c) 2020 Hirotsuna Mizuno. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package speedio_test
import (
"io"
"testing"
"github.com/tunabay/go-randdata"
"github.com/tunabay/go-speedio"
)
//
func TestLimiterReader_test1(t *testing.T) {
t.Parallel()
rd := randdata.New(randdata.Binary, 0, 5)
r, err := speedio.NewLimiterReader(rd, 16)
if err != nil {
t.Error(err)
return
}
buf := make([]byte, 1024)
sum := 0
for {
n, err := r.Read(buf)
if 0 < n {
sum += n
}
if err != nil {
if err != io.EOF {
t.Error(err)
}
break
}
}
r.Close()
if sum != 5 {
t.Errorf("unexpected data len: want=5, got=%d", sum)
}
}
//
func TestLimiterReader_test2(t *testing.T) {
t.Parallel()
rd := randdata.New(randdata.Binary, 0, 5)
_, err := speedio.NewLimiterReader(rd, 1)
if err == nil {
t.Errorf("error expected")
return
}
}