@@ -120,6 +120,12 @@ func setupForAuthorityTests(ctx context.Context, t *testing.T, idleTimeout time.
120120 return lisDefault , lisNonDefault , client , close
121121}
122122
123+ type noopClusterWatcher struct {}
124+
125+ func (noopClusterWatcher ) OnUpdate (update * xdsresource.ClusterResourceData ) {}
126+ func (noopClusterWatcher ) OnError (err error ) {}
127+ func (noopClusterWatcher ) OnResourceDoesNotExist () {}
128+
123129// TestAuthorityShare tests the authority sharing logic. The test verifies the
124130// following scenarios:
125131// - A watch for a resource name with an authority matching an existing watch
@@ -143,14 +149,15 @@ func (s) TestAuthorityShare(t *testing.T) {
143149 }
144150
145151 // Request the first resource. Verify that a new transport is created.
146- cdsCancel1 := client .WatchCluster (authorityTestResourceName11 , func (u xdsresource.ClusterUpdate , err error ) {})
152+ watcher := noopClusterWatcher {}
153+ cdsCancel1 := xdsresource .WatchCluster (client , authorityTestResourceName11 , watcher )
147154 defer cdsCancel1 ()
148155 if _ , err := lis .NewConnCh .Receive (ctx ); err != nil {
149156 t .Fatalf ("Timed out when waiting for a new transport to be created to the management server: %v" , err )
150157 }
151158
152159 // Request the second resource. Verify that no new transport is created.
153- cdsCancel2 := client .WatchCluster (authorityTestResourceName12 , func ( u xdsresource. ClusterUpdate , err error ) {} )
160+ cdsCancel2 := xdsresource .WatchCluster (client , authorityTestResourceName12 , watcher )
154161 defer cdsCancel2 ()
155162 sCtx , sCancel = context .WithTimeout (ctx , defaultTestShortTimeout )
156163 defer sCancel ()
@@ -159,7 +166,7 @@ func (s) TestAuthorityShare(t *testing.T) {
159166 }
160167
161168 // Request the third resource. Verify that no new transport is created.
162- cdsCancel3 := client .WatchCluster (authorityTestResourceName2 , func ( u xdsresource. ClusterUpdate , err error ) {} )
169+ cdsCancel3 := xdsresource .WatchCluster (client , authorityTestResourceName2 , watcher )
163170 defer cdsCancel3 ()
164171 sCtx , sCancel = context .WithTimeout (ctx , defaultTestShortTimeout )
165172 defer sCancel ()
@@ -179,15 +186,16 @@ func (s) TestAuthorityIdleTimeout(t *testing.T) {
179186 defer close ()
180187
181188 // Request the first resource. Verify that a new transport is created.
182- cdsCancel1 := client .WatchCluster (authorityTestResourceName11 , func (u xdsresource.ClusterUpdate , err error ) {})
189+ watcher := noopClusterWatcher {}
190+ cdsCancel1 := xdsresource .WatchCluster (client , authorityTestResourceName11 , watcher )
183191 val , err := lis .NewConnCh .Receive (ctx )
184192 if err != nil {
185193 t .Fatalf ("Timed out when waiting for a new transport to be created to the management server: %v" , err )
186194 }
187195 conn := val .(* testutils.ConnWrapper )
188196
189197 // Request the second resource. Verify that no new transport is created.
190- cdsCancel2 := client .WatchCluster (authorityTestResourceName12 , func ( u xdsresource. ClusterUpdate , err error ) {} )
198+ cdsCancel2 := xdsresource .WatchCluster (client , authorityTestResourceName12 , watcher )
191199 sCtx , sCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
192200 defer sCancel ()
193201 if _ , err := lis .NewConnCh .Receive (sCtx ); err != context .DeadlineExceeded {
@@ -225,7 +233,8 @@ func (s) TestAuthorityClientClose(t *testing.T) {
225233
226234 // Request the first resource. Verify that a new transport is created to the
227235 // default management server.
228- cdsCancel1 := client .WatchCluster (authorityTestResourceName11 , func (u xdsresource.ClusterUpdate , err error ) {})
236+ watcher := noopClusterWatcher {}
237+ cdsCancel1 := xdsresource .WatchCluster (client , authorityTestResourceName11 , watcher )
229238 val , err := lisDefault .NewConnCh .Receive (ctx )
230239 if err != nil {
231240 t .Fatalf ("Timed out when waiting for a new transport to be created to the management server: %v" , err )
@@ -235,7 +244,7 @@ func (s) TestAuthorityClientClose(t *testing.T) {
235244 // Request another resource which is served by the non-default authority.
236245 // Verify that a new transport is created to the non-default management
237246 // server.
238- client .WatchCluster (authorityTestResourceName3 , func ( u xdsresource. ClusterUpdate , err error ) {} )
247+ xdsresource .WatchCluster (client , authorityTestResourceName3 , watcher )
239248 val , err = lisNonDefault .NewConnCh .Receive (ctx )
240249 if err != nil {
241250 t .Fatalf ("Timed out when waiting for a new transport to be created to the management server: %v" , err )
@@ -272,7 +281,8 @@ func (s) TestAuthorityRevive(t *testing.T) {
272281 defer close ()
273282
274283 // Request the first resource. Verify that a new transport is created.
275- cdsCancel1 := client .WatchCluster (authorityTestResourceName11 , func (u xdsresource.ClusterUpdate , err error ) {})
284+ watcher := noopClusterWatcher {}
285+ cdsCancel1 := xdsresource .WatchCluster (client , authorityTestResourceName11 , watcher )
276286 val , err := lis .NewConnCh .Receive (ctx )
277287 if err != nil {
278288 t .Fatalf ("Timed out when waiting for a new transport to be created to the management server: %v" , err )
@@ -284,7 +294,7 @@ func (s) TestAuthorityRevive(t *testing.T) {
284294
285295 // Request the second resource. Verify that no new transport is created.
286296 // This should move the authority out of the idle cache.
287- cdsCancel2 := client .WatchCluster (authorityTestResourceName12 , func ( u xdsresource. ClusterUpdate , err error ) {} )
297+ cdsCancel2 := xdsresource .WatchCluster (client , authorityTestResourceName12 , watcher )
288298 defer cdsCancel2 ()
289299 sCtx , sCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
290300 defer sCancel ()
0 commit comments