-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage_test.go
82 lines (66 loc) · 1.63 KB
/
storage_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
package microbatch
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_NewInMemoryStorage_creates_storage(t *testing.T) {
st := NewInMemoryStorage[any, any](1)
assert.NotNil(t, st)
}
func Test_Append_appends_job(t *testing.T) {
st := NewInMemoryStorage[any, any](1)
job := func(t any) *JobResult[any] {
return &JobResult[any]{}
}
err := st.Append(job)
assert.Nil(t, err)
}
func Test_Append_errors_on_limit(t *testing.T) {
st := NewInMemoryStorage[any, any](1)
job1 := func(t any) *JobResult[any] {
return &JobResult[any]{}
}
job2 := func(t any) *JobResult[any] {
return &JobResult[any]{}
}
err := st.Append(job1)
assert.Nil(t, err)
err = st.Append(job2)
assert.NotNil(t, err)
assert.Equal(t, ErrStorageFull, err)
}
func Test_Size_returns_current_size(t *testing.T) {
st := NewInMemoryStorage[any, any](5)
job := func(t any) *JobResult[any] {
return &JobResult[any]{}
}
st.Append(job)
assert.Equal(t, 1, st.Size())
}
func Test_GetAll_returns_all_jobs(t *testing.T) {
st := NewInMemoryStorage[any, any](5)
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
assert.Equal(t, 3, st.Size())
}
func Test_Clear_clears_storage(t *testing.T) {
st := NewInMemoryStorage[any, any](5)
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
st.Append(func(t any) *JobResult[any] {
return &JobResult[any]{}
})
st.Clear()
assert.Equal(t, 0, st.Size())
}