-
Notifications
You must be signed in to change notification settings - Fork 5
/
filter_test.go
49 lines (45 loc) · 1016 Bytes
/
filter_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
package spool
import (
"testing"
"time"
"github.com/cloudspannerecosystem/spool/model"
)
func TestFilterNotUsedWithin(t *testing.T) {
now := time.Now()
hour := time.Hour
sdbs := []*model.SpoolDatabase{
{
UpdatedAt: now.Add(-hour),
},
{
UpdatedAt: now.Add(-hour).Add(time.Second),
},
}
filtered := filter(sdbs, FilterNotUsedWithin(hour))
if len(filtered) != 1 {
t.Errorf("expected 1 but got %d", len(filtered))
} else {
if !filtered[0].UpdatedAt.Equal(sdbs[0].UpdatedAt) {
t.Errorf("expected %s but got %s", sdbs[0].UpdatedAt, filtered[0].UpdatedAt)
}
}
}
func TestFilterState(t *testing.T) {
sdbs := []*model.SpoolDatabase{
{
State: StateIdle.Int64(),
},
{
State: StateBusy.Int64(),
},
}
state := StateIdle
filtered := filter(sdbs, FilterState(state))
if len(filtered) != 1 {
t.Errorf("expected 1 but got %d", len(filtered))
} else {
if filtered[0].State != state.Int64() {
t.Errorf("expected %s but got %s", state, State(filtered[0].State))
}
}
}