forked from fynelabs/selfupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress_test.go
50 lines (41 loc) · 1.1 KB
/
progress_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
package selfupdate
import (
"bytes"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ProgressReaderWithContentLength(t *testing.T) {
data := []byte("this is some test data that should arrive on the other end of the pipe")
reader := bytes.NewReader(data)
var lastPercentage float64
pr := progressReader{
Reader: reader,
contentLength: int64(len(data)),
progressCallback: func(f float64, err error) {
lastPercentage = f
},
}
r, err := ioutil.ReadAll(&pr)
assert.NotNil(t, r)
assert.Nil(t, err)
assert.Equal(t, float64(1), lastPercentage)
assert.Equal(t, data, r)
}
func Test_ProgressReaderWithoutContentLength(t *testing.T) {
data := []byte("this is some test data that should arrive on the other end of the pipe")
reader := bytes.NewReader(data)
var lastPercentage float64
pr := progressReader{
Reader: reader,
contentLength: 0,
progressCallback: func(f float64, err error) {
lastPercentage = f
},
}
r, err := ioutil.ReadAll(&pr)
assert.NotNil(t, r)
assert.Nil(t, err)
assert.Equal(t, float64(1), lastPercentage)
assert.Equal(t, data, r)
}