-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogress_test.go
More file actions
48 lines (36 loc) · 810 Bytes
/
progress_test.go
File metadata and controls
48 lines (36 loc) · 810 Bytes
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
package progress
import (
"fmt"
"io"
"io/ioutil"
"os"
. "testing"
"time"
. "gopkg.in/check.v1"
)
type progressSuite struct{}
var _ = Suite(&progressSuite{})
func TestProgress(t *T) {
TestingT(t)
}
func (p *progressSuite) TestMeterReporting(c *C) {
zero, err := os.Open("/dev/zero")
c.Assert(err, IsNil)
r := NewReader("test", zero, 100*time.Millisecond)
go io.Copy(ioutil.Discard, r)
now := time.Now()
var i int
for tick := range r.C {
if i > 0 {
offset := tick.Time.Sub(now)
fmt.Println(offset)
c.Assert(offset > time.Duration(i)*100*time.Millisecond && offset < time.Duration(i+1)*100*time.Millisecond, Equals, true)
}
c.Assert(tick.Artifact, Equals, "test")
i++
if i > 10 {
r.Close()
}
}
c.Assert(time.Since(now) < 1500*time.Millisecond, Equals, true)
}