@@ -207,7 +207,22 @@ func deleteSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlati
207207 }
208208}
209209
210- func validateEvents (t * testing.T , subClient pb.GrpcGateway_SubscribeToEventsClient , expectedEvents map [string ]* pb.Event , failOnUnexpectedEvent bool ) {
210+ func batchDeleteSwitchChangedResourceExpected (t * testing.T , deviceID , subID , correlationID , switchID string ) map [string ]* pb.Event {
211+
212+ changed := & pb.Event {
213+ SubscriptionId : subID ,
214+ CorrelationId : correlationID ,
215+ Type : & pb.Event_ResourceChanged {
216+ ResourceChanged : pbTest .MakeResourceChanged (t , deviceID , test .TestResourceSwitchesInstanceHref (switchID ), "" , map [interface {}]interface {}{}),
217+ },
218+ }
219+
220+ return map [string ]* pb.Event {
221+ pbTest .GetEventID (changed ): changed ,
222+ }
223+ }
224+
225+ func validateEvents (t * testing.T , subClient pb.GrpcGateway_SubscribeToEventsClient , expectedEvents map [string ]* pb.Event ) {
211226 for {
212227 ev , err := subClient .Recv ()
213228 if kitNetGrpc .IsContextDeadlineExceeded (err ) {
@@ -218,10 +233,6 @@ func validateEvents(t *testing.T, subClient pb.GrpcGateway_SubscribeToEventsClie
218233 eventID := pbTest .GetEventID (ev )
219234 expected , ok := expectedEvents [eventID ]
220235 if ! ok {
221- if ! failOnUnexpectedEvent {
222- t .Logf ("unexpected event received: %+v" , ev )
223- continue
224- }
225236 require .Failf (t , "unexpected event" , "invalid event: %+v" , ev )
226237 }
227238 pbTest .CmpEvent (t , expected , ev , "" )
@@ -258,13 +269,20 @@ func TestCreateAndDeleteResource(t *testing.T) {
258269 subClient , subID := subscribeToAllEvents (t , ctx , c , correlationID )
259270 const switchID = "1"
260271
272+ isDiscoveryResourceBatchObservable := test .IsDiscoveryResourceBatchObservable (ctx , t , deviceID )
273+
261274 for i := 0 ; i < 5 ; i ++ {
262275 fmt .Printf ("iteration %v\n " , i )
263276 createSwitchResource (t , ctx , c , deviceID , switchID )
264277 expectedCreateEvents := createSwitchResourceExpectedEvents (t , deviceID , subID , correlationID , switchID )
265- validateEvents (t , subClient , expectedCreateEvents , true )
278+ validateEvents (t , subClient , expectedCreateEvents )
266279 deleteSwitchResource (t , ctx , c , deviceID , switchID )
267280 expectedDeleteEvents := deleteSwitchResourceExpectedEvents (t , deviceID , subID , correlationID , switchID )
268- validateEvents (t , subClient , expectedDeleteEvents , false )
281+ validateEvents (t , subClient , expectedDeleteEvents )
282+
283+ if isDiscoveryResourceBatchObservable {
284+ expectedEvents := batchDeleteSwitchChangedResourceExpected (t , deviceID , subID , correlationID , switchID )
285+ validateEvents (t , subClient , expectedEvents )
286+ }
269287 }
270288}
0 commit comments