-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstatus_test.go
83 lines (79 loc) · 1.88 KB
/
status_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
package swiftlygo_test
import (
"github.com/ibmjstart/swiftlygo"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Status", func() {
var (
s *swiftlygo.Status
out chan string
numberUploads, uploadSize uint
)
BeforeEach(func() {
out = make(chan string)
numberUploads = 3
uploadSize = 1024
s = swiftlygo.NewStatus(numberUploads, uploadSize, out)
})
Context("Before Print() is called", func() {
It("Should not write a string to the output channel", func() {
Eventually(out).
ShouldNot(Receive(BeAssignableToTypeOf("string")))
})
})
Context("When Print() is called before Start()", func() {
It("Writes a string to the output channel", func() {
go func() {
s.Print()
}()
Eventually(out).
Should(Receive(BeAssignableToTypeOf("string")))
})
})
Context("When Print() is called after Start()", func() {
It("Writes a string to the output channel for each call to Print()",
func() {
s.Start()
const prints = 5
go func() {
for i := 0; i < prints; i++ {
s.Print()
}
}()
seen := 0
abort := time.NewTicker(time.Second)
for i := 0; i < prints; i++ {
select {
case <-out:
seen++
case <-abort.C:
abort.Stop()
Fail("Test took too long")
}
}
Expect(seen).Should(Equal(prints))
})
})
Context("When UploadComplete is called", func() {
It("Should change the PercentComplete()", func() {
s.Start()
initial := s.PercentComplete()
s.UploadComplete()
Expect(initial).ShouldNot(Equal(s.PercentComplete()))
})
})
Context("When Print() is called after Stop()", func() {
It("Writes a string to the output channel", func() {
s.Start()
time.Sleep(time.Second)
s.Stop()
go func() {
s.Print()
}()
Eventually(out).
Should(Receive(BeAssignableToTypeOf("string")))
})
})
})