()
| 1180 | } |
| 1181 | |
| 1182 | func (s *WatcherTestSuite) TestWithUserIDFilter() { |
| 1183 | producer, err := watcher.RegisterProducer(s.ctx, "test-producer") |
| 1184 | s.Require().NoError(err) |
| 1185 | s.Require().NotNil(producer) |
| 1186 | |
| 1187 | userID, err := uuid.NewUUID() |
| 1188 | s.Require().NoError(err) |
| 1189 | |
| 1190 | userID2, err := uuid.NewUUID() |
| 1191 | s.Require().NoError(err) |
| 1192 | |
| 1193 | consumer, err := watcher.RegisterConsumer( |
| 1194 | s.ctx, "test-consumer", |
| 1195 | watcher.WithUserIDFilter(userID.String()), |
| 1196 | ) |
| 1197 | s.Require().NoError(err) |
| 1198 | s.Require().NotNil(consumer) |
| 1199 | consumeEvents(consumer) |
| 1200 | |
| 1201 | payload := common.ChangePayload{ |
| 1202 | EntityType: common.UserEntityType, |
| 1203 | Operation: common.UpdateOperation, |
| 1204 | Payload: params.User{ |
| 1205 | ID: userID.String(), |
| 1206 | }, |
| 1207 | } |
| 1208 | err = producer.Notify(payload) |
| 1209 | s.Require().NoError(err) |
| 1210 | |
| 1211 | receivedPayload := waitForPayload(consumer.Watch(), 100*time.Millisecond) |
| 1212 | s.Require().NotNil(receivedPayload) |
| 1213 | s.Require().Equal(payload, *receivedPayload) |
| 1214 | |
| 1215 | payload = common.ChangePayload{ |
| 1216 | EntityType: common.UserEntityType, |
| 1217 | Operation: common.UpdateOperation, |
| 1218 | Payload: params.User{ |
| 1219 | ID: userID2.String(), |
| 1220 | }, |
| 1221 | } |
| 1222 | |
| 1223 | err = producer.Notify(payload) |
| 1224 | s.Require().NoError(err) |
| 1225 | receivedPayload = waitForPayload(consumer.Watch(), 100*time.Millisecond) |
| 1226 | s.Require().Nil(receivedPayload) |
| 1227 | |
| 1228 | payload = common.ChangePayload{ |
| 1229 | EntityType: common.UserEntityType, |
| 1230 | Operation: common.UpdateOperation, |
| 1231 | // Declare as user, but payload is a pool. Filter should return false. |
| 1232 | Payload: params.Pool{}, |
| 1233 | } |
| 1234 | |
| 1235 | err = producer.Notify(payload) |
| 1236 | s.Require().NoError(err) |
| 1237 | receivedPayload = waitForPayload(consumer.Watch(), 100*time.Millisecond) |
| 1238 | s.Require().Nil(receivedPayload) |
| 1239 | } |
nothing calls this directly
no test coverage detected