-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelement_test.go
60 lines (52 loc) · 1.05 KB
/
element_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
package main
import (
"testing"
"time"
)
func TestRunning(t *testing.T) {
e := Element{
ID: 1,
Name: "TestElement",
Start: time.Now(),
}
if !e.IsRunning() {
t.Error("Element should be running but IsRunning returned false")
}
}
func TestNotRunning(t *testing.T) {
e := Element{
ID: 1,
Name: "TestElement",
Start: time.Now(),
End: time.Now().Add(time.Minute * 5),
}
if e.IsRunning() {
t.Error("Element has End time, but IsRunning returned true")
}
}
func TestDuration(t *testing.T) {
now := time.Now()
e := Element{
ID: 1,
Name: "TestElement",
Start: now,
End: now.Add(time.Minute * 5),
}
if e.Duration() != time.Minute*5 {
t.Error("Element should have 5 minute duration. Actual: ", e.Duration())
}
}
func TestRunningDuration(t *testing.T) {
now := time.Now()
e := Element{
ID: 1,
Name: "TestElement",
Start: now,
}
d1 := e.Duration()
time.Sleep(time.Millisecond * 50)
d2 := e.Duration()
if d2 <= d1 {
t.Errorf("For running task Duration should be increase. D1: %v, D2: %v\n", d1, d2)
}
}