@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"testing"
22
22
23
+ "github.com/davecgh/go-spew/spew"
23
24
. "github.com/onsi/gomega"
24
25
corev1 "k8s.io/api/core/v1"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -81,7 +82,7 @@ func TestClusterCacheTracker(t *testing.T) {
81
82
go func () {
82
83
g .Expect (mgr .Start (mgrContext )).To (Succeed ())
83
84
}()
84
- <- env . Manager .Elected ()
85
+ <- mgr .Elected ()
85
86
86
87
k8sClient = mgr .GetClient ()
87
88
@@ -115,11 +116,14 @@ func TestClusterCacheTracker(t *testing.T) {
115
116
116
117
teardown := func (t * testing.T , g * WithT , ns * corev1.Namespace ) {
117
118
t .Helper ()
119
+ defer close (c .ch )
118
120
119
121
t .Log ("Deleting any Secrets" )
120
122
g .Expect (cleanupTestSecrets (ctx , k8sClient )).To (Succeed ())
121
123
t .Log ("Deleting any Clusters" )
122
124
g .Expect (cleanupTestClusters (ctx , k8sClient )).To (Succeed ())
125
+ g .Expect (<- c .ch ).To (Equal ("mapped-" + clusterA .Name ))
126
+ g .Consistently (c .ch ).ShouldNot (Receive ())
123
127
t .Log ("Deleting Namespace" )
124
128
g .Expect (env .Delete (ctx , ns )).To (Succeed ())
125
129
t .Log ("Stopping the manager" )
@@ -144,9 +148,7 @@ func TestClusterCacheTracker(t *testing.T) {
144
148
g .Expect (<- c .ch ).To (Equal ("mapped-" + clusterA .Name ))
145
149
146
150
t .Log ("Ensuring no additional watch notifications arrive" )
147
- g .Consistently (func () int {
148
- return len (c .ch )
149
- }).Should (Equal (0 ))
151
+ g .Consistently (c .ch ).ShouldNot (Receive ())
150
152
151
153
t .Log ("Updating the cluster" )
152
154
clusterA .Annotations = map [string ]string {
@@ -158,9 +160,7 @@ func TestClusterCacheTracker(t *testing.T) {
158
160
g .Expect (<- c .ch ).To (Equal ("mapped-" + clusterA .Name ))
159
161
160
162
t .Log ("Ensuring no additional watch notifications arrive" )
161
- g .Consistently (func () int {
162
- return len (c .ch )
163
- }).Should (Equal (0 ))
163
+ g .Consistently (c .ch ).ShouldNot (Receive ())
164
164
165
165
t .Log ("Creating the same watch a second time" )
166
166
g .Expect (cct .Watch (ctx , WatchInput {
@@ -172,9 +172,7 @@ func TestClusterCacheTracker(t *testing.T) {
172
172
})).To (Succeed ())
173
173
174
174
t .Log ("Ensuring no additional watch notifications arrive" )
175
- g .Consistently (func () int {
176
- return len (c .ch )
177
- }).Should (Equal (0 ))
175
+ g .Consistently (c .ch ).ShouldNot (Receive ())
178
176
179
177
t .Log ("Updating the cluster" )
180
178
clusterA .Annotations ["update1" ] = "2"
@@ -184,9 +182,7 @@ func TestClusterCacheTracker(t *testing.T) {
184
182
g .Expect (<- c .ch ).To (Equal ("mapped-" + clusterA .Name ))
185
183
186
184
t .Log ("Ensuring no additional watch notifications arrive" )
187
- g .Consistently (func () int {
188
- return len (c .ch )
189
- }).Should (Equal (0 ))
185
+ g .Consistently (c .ch ).ShouldNot (Receive ())
190
186
})
191
187
})
192
188
}
@@ -196,7 +192,11 @@ type testController struct {
196
192
}
197
193
198
194
func (c * testController ) Reconcile (ctx context.Context , req reconcile.Request ) (reconcile.Result , error ) {
199
- c .ch <- req .Name
195
+ spew .Dump (req )
196
+ select {
197
+ case <- ctx .Done ():
198
+ case c .ch <- req .Name :
199
+ }
200
200
return ctrl.Result {}, nil
201
201
}
202
202
0 commit comments