-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_list_test.go
91 lines (74 loc) · 1.27 KB
/
build_list_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
84
85
86
87
88
89
90
91
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAdd(t *testing.T) {
l := New()
assert.True(t, l.Add("proj1", 1))
assert.False(t, l.Add("proj1", 1))
assert.True(t, l.Add("proj1", 2))
assert.True(t, l.Add("proj1", 4))
assert.True(t, l.Add("proj1", 3))
assert.True(t, l.Add("proj2", 1))
}
func TestCleanup(t *testing.T) {
l := New()
data := []struct {
project string
buildNum int
}{
{
project: "proj1",
buildNum: 5,
},
{
project: "proj1",
buildNum: 6,
},
{
project: "proj2",
buildNum: 3,
},
{
project: "proj2",
buildNum: 4,
},
{
project: "proj4",
buildNum: 10,
},
}
data2 := []struct {
project string
buildNum int
}{
{
project: "later1",
buildNum: 11,
},
{
project: "proj2",
buildNum: 7,
},
}
for _, d := range data {
l.Add(d.project, d.buildNum)
}
now := time.Now()
l.Cleanup(now.Add(-time.Hour), nil)
assert.Equal(t, len(data), l.size())
l.Cleanup(now.Add(time.Hour), nil)
assert.Equal(t, 0, l.size())
for _, d := range data {
l.Add(d.project, d.buildNum)
}
now = time.Now()
time.Sleep(time.Second)
for _, d := range data2 {
l.Add(d.project, d.buildNum)
}
l.Cleanup(now, nil)
assert.Equal(t, len(data2), l.size())
}