-
Notifications
You must be signed in to change notification settings - Fork 3
/
dispatcher_test.go
58 lines (46 loc) · 1.3 KB
/
dispatcher_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
package carrot
import (
"testing"
)
func TestDispatchRequest(t *testing.T) {
d := NewDispatcher()
token1, route1, req1, err := getTokenRouteAndRequestForTest(endpoint1)
if err != nil {
t.Error(err)
}
key1 := getCacheKey(token1, route1.controller)
if d.cachedControllers.Exists(key1) {
t.Fatalf("The DPC is already in the cached controllers list")
}
if d.cachedControllers.Length() != 0 {
t.Fatalf("No (zero) cached controllers should be stored yet")
}
err = d.dispatchRequest(route1, req1)
if err != nil {
t.Fatal(err)
}
if !d.cachedControllers.Exists(key1) {
t.Fatalf("The DPC was unsuccessfully stored in the cached controllers list")
}
if d.cachedControllers.Length() != 1 {
t.Fatalf("Only 1 (one) cached controller should be stored")
}
err = d.dispatchRequest(route1, req1)
if err != nil {
t.Fatal(err)
}
if d.cachedControllers.Length() != 1 { //should return int of 1 (using existing entry in list)
t.Fatalf("An existing cached controller should have been used")
}
_, route2, req2, err := getTokenRouteAndRequestForTest(endpoint1)
if err != nil {
t.Error(err)
}
err = d.dispatchRequest(route2, req2)
if err != nil {
t.Fatal(err)
}
if d.cachedControllers.Length() != 2 { //should return int of 2
t.Fatalf("Only 2 (two) cached controllers should be stored")
}
}