-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_test.go
71 lines (66 loc) · 1.43 KB
/
model_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
package pagorminator
import "testing"
func TestPagination_UnPaged(t *testing.T) {
t.Parallel()
tests := map[string]struct {
page int
size int
expected bool
}{
"page 0 size 0": {
page: 0,
size: 0,
expected: true,
},
"page zero size not zero": {
page: 0,
size: 1,
expected: false,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
page, err := PageRequest(test.page, test.size)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if page.IsUnPaged() != test.expected {
t.Errorf("IsUnPaged() expected %v, got %v", test.expected, page.IsUnPaged())
}
})
}
}
func TestPagination_CalculateTotalPages(t *testing.T) {
t.Parallel()
tests := map[string]struct {
totalElements int64
size int
expected int
}{
"totalElements lower than size": {
totalElements: 2,
size: 4,
expected: 1,
},
"totalElements greater and not divisible by size": {
totalElements: 3,
size: 2,
expected: 2,
},
"totalElements greater and divisible by size": {
totalElements: 4,
size: 2,
expected: 2,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
actual := calculateTotalPages(test.totalElements, test.size)
if actual != test.expected {
t.Errorf("totalPages expected %v, got %v", test.expected, actual)
}
})
}
}