-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggl_duration_test.go
57 lines (51 loc) · 1.42 KB
/
toggl_duration_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
package timenote_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"livingit.de/code/timenote"
"testing"
)
func dotest(n int64, exp string) {
td, _ := timenote.NewTogglDuration(n)
Expect(td.String()).To(Equal(exp))
}
func dotestnoseconds(n int64, exp string) {
td, _ := timenote.NewTogglDuration(n)
td.OmitSeconds()
Expect(td.String()).To(Equal(exp))
}
func dotesterror(n int64, exp string) {
_, err := timenote.NewTogglDuration(n)
errText := "no error"
if err != nil {
errText = err.Error()
}
Expect(errText).To(Equal(exp))
}
var _ = Describe("Human readable duration in seconds", func() {
It("should handle finished tasks", func() {
dotest(10, "10s")
dotest(60, "1m 00s")
dotest(3600, "1h 00m 00s")
dotest(3666, "1h 01m 06s")
dotest(3600*24, "1d 0h 00m 00s")
})
It("should omit seconds when asked", func() {
dotestnoseconds(10, "<1m")
dotestnoseconds(60, "1m")
dotestnoseconds(3600, "1h 00m")
dotestnoseconds(3666, "1h 01m")
dotestnoseconds(3600*24, "1d 0h 00m")
})
It("should handle open tasks", func() {
dotesterror(-10, "negative values not allowed")
dotesterror(-60, "negative values not allowed")
dotesterror(-3600, "negative values not allowed")
dotesterror(-3666, "negative values not allowed")
dotesterror(-3600*24, "negative values not allowed")
})
})
func TestFormat(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Human readable duration in seconds")
}