forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_test.go
98 lines (85 loc) · 2.33 KB
/
controller_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package controller
import (
"testing"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/watch"
routeapi "github.com/openshift/origin/pkg/route/api"
)
type fakeRouterPlugin struct {
lastSyncProcessed bool
syncedAtLeastOnce bool
}
func (p *fakeRouterPlugin) HandleRoute(t watch.EventType, route *routeapi.Route) error {
return nil
}
func (p *fakeRouterPlugin) HandleNode(t watch.EventType, node *kapi.Node) error {
return nil
}
func (p *fakeRouterPlugin) HandleEndpoints(watch.EventType, *kapi.Endpoints) error {
return nil
}
func (p *fakeRouterPlugin) HandleNamespaces(namespaces sets.String) error {
return nil
}
func (p *fakeRouterPlugin) SetLastSyncProcessed(processed bool) error {
p.lastSyncProcessed = processed
return nil
}
func (p *fakeRouterPlugin) SetSyncedAtLeastOnce() error {
p.syncedAtLeastOnce = true
return nil
}
type fakeNamespaceLister struct {
}
func (n fakeNamespaceLister) NamespaceNames() (sets.String, error) {
return sets.NewString("foo"), nil
}
func TestRouterController_updateLastSyncProcessed(t *testing.T) {
p := fakeRouterPlugin{}
routesListConsumed := true
c := RouterController{
Plugin: &p,
NextEndpoints: func() (watch.EventType, *kapi.Endpoints, error) {
return watch.Modified, &kapi.Endpoints{}, nil
},
NextRoute: func() (watch.EventType, *routeapi.Route, error) {
return watch.Modified, &routeapi.Route{}, nil
},
NextNode: func() (watch.EventType, *kapi.Node, error) {
return watch.Modified, &kapi.Node{}, nil
},
EndpointsListConsumed: func() bool {
return true
},
RoutesListConsumed: func() bool {
return routesListConsumed
},
Namespaces: fakeNamespaceLister{},
NamespaceRetries: 1,
}
// Simulate the initial sync
c.HandleNamespaces()
if p.lastSyncProcessed {
t.Fatalf("last sync not expected to have been processed")
}
c.HandleEndpoints()
if p.lastSyncProcessed {
t.Fatalf("last sync not expected to have been processed")
}
c.HandleRoute()
if !p.lastSyncProcessed {
t.Fatalf("last sync expected to have been processed")
}
// Simulate a relist
routesListConsumed = false
c.HandleRoute()
if p.lastSyncProcessed {
t.Fatalf("last sync not expected to have been processed")
}
routesListConsumed = true
c.HandleRoute()
if !p.lastSyncProcessed {
t.Fatalf("last sync expected to have been processed")
}
}