-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_test.go
72 lines (56 loc) · 1.78 KB
/
queue_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
package grazer
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tj/assert"
)
func Test_queue_enqueue(t *testing.T) {
t.Run("simple", func(t *testing.T) {
q := newQueue()
q.enqueue([]string{"/contact"}, []string{"/about", "/home"})
assertPop(t, q, "/contact")
assertPop(t, q, "/about")
assertPop(t, q, "/home")
})
t.Run("multiple will combine priority, keep unique", func(t *testing.T) {
q := newQueue()
q.enqueue([]string{"/contact"}, []string{"/about", "/home"})
q.enqueue([]string{"/about"}, []string{"/contact", "/home"})
assertPop(t, q, "/contact")
assertPop(t, q, "/about")
assertPop(t, q, "/home")
assert.Nil(t, q.pop())
})
t.Run("intermittent 1", func(t *testing.T) {
q := newQueue()
q.enqueue([]string{"/contact", "/support"}, []string{"/about", "/home", "/imprint"})
assertPop(t, q, "/contact")
q.enqueue([]string{"/imprint", "/contact"}, []string{"/about", "/home", "/support"})
assertPop(t, q, "/support")
assertPop(t, q, "/contact")
assertPop(t, q, "/imprint")
assertPop(t, q, "/about")
assertPop(t, q, "/home")
assert.Nil(t, q.pop())
})
t.Run("intermittent 2", func(t *testing.T) {
q := newQueue()
q.enqueue([]string{"/contact", "/support"}, []string{"/about", "/home", "/imprint"})
assertPop(t, q, "/contact")
assertPop(t, q, "/support")
assertPop(t, q, "/about")
q.enqueue([]string{"/imprint", "/contact"}, []string{"/about", "/home", "/support"})
assertPop(t, q, "/contact")
assertPop(t, q, "/imprint")
assertPop(t, q, "/about")
assertPop(t, q, "/home")
assertPop(t, q, "/support")
assert.Nil(t, q.pop())
})
}
func assertPop(t *testing.T, q *queue, expectedRoutePath string) {
t.Helper()
routePath := q.pop()
require.NotNil(t, routePath)
assert.Equal(t, expectedRoutePath, *routePath)
}