aleios-cloud / aleios-cloud/sls-test-tools

getEvents method name unclear

Đang mở
#15 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
195
Fork
20
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi :)

I have used the lib in a use case when several events are sent to EventBridge, I thought that the getEvents method would fetch them all (until the queue was empty). But instead, it only fetched the messages one by one. This was quite confusing since the plural in the name of the method lead me to think it would fetch all the events fired so far. This confusion caused many failure in my test suite, which were difficult to debug.

So, in the end, I implemented a method like so to fetch all events in one function call:

```typescript
static async getAllEventBridgeMessages(): Promise {
if (EventBridgeTestUtil.eventBridge === null) {
throw new Error("EventBridgeTestUtil has not been setup");
}

let result: EventBridgeMessage[] = [];
let lastResults: EventBridgeMessage[] = [];

do {
try {
const events = await EventBridgeTestUtil.eventBridge.getEvents();
lastResults = events.Messages;
result = [...result, ...lastResults];
} catch (e) {
lastResults = [];
}
} while (lastResults.length !== 0);

return result;
}
```

It would be great if `getEvents` could be renamed to be clearer, such as `getEvent` and if a method `getAllEvents` could be implemented :)

Thanks ;)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.