Skip to content

Commit

Permalink
fix(eventstream-serde-universal): mark test code for exclusion (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Aug 7, 2024
1 parent e77488b commit b352cc1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-balloons-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/eventstream-serde-universal": patch
---

exclude test code from artifact

This file was deleted.

31 changes: 0 additions & 31 deletions packages/eventstream-serde-universal/src/fixtures/event.fixture.ts

This file was deleted.

66 changes: 64 additions & 2 deletions packages/eventstream-serde-universal/src/getChunkedStream.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,69 @@
import { endEventMessage, recordEventMessage, statsEventMessage } from "./fixtures/event.fixture";
import { MockEventMessageSource } from "./fixtures/MockEventMessageSource.fixture";
import { Readable, ReadableOptions } from "stream";

import { getChunkedStream } from "./getChunkedStream";

export const recordEventMessage = Buffer.from(
"AAAA0AAAAFX31gVLDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB1JlY29yZHMNOmNvbnRlbnQtdHlwZQcAGGFwcGxpY2F0aW9uL29jdGV0LXN0cmVhbTEsRm9vLFdoZW4gbGlmZSBnaXZlcyB5b3UgZm9vLi4uCjIsQmFyLG1ha2UgQmFyIQozLEZpenosU29tZXRpbWVzIHBhaXJlZCB3aXRoLi4uCjQsQnV6eix0aGUgaW5mYW1vdXMgQnV6eiEKzxKeSw==",
"base64"
);

export const statsEventMessage = Buffer.from(
"AAAA0QAAAEM+YpmqDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcABVN0YXRzDTpjb250ZW50LXR5cGUHAAh0ZXh0L3htbDxTdGF0cyB4bWxucz0iIj48Qnl0ZXNTY2FubmVkPjEyNjwvQnl0ZXNTY2FubmVkPjxCeXRlc1Byb2Nlc3NlZD4xMjY8L0J5dGVzUHJvY2Vzc2VkPjxCeXRlc1JldHVybmVkPjEwNzwvQnl0ZXNSZXR1cm5lZD48L1N0YXRzPiJ0pLk=",
"base64"
);

export const endEventMessage = Buffer.from(
"AAAAOAAAACjBxoTUDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAA0VuZM+X05I=",
"base64"
);

export const exception = Buffer.from(
"AAAAtgAAAF8BcW64DTpjb250ZW50LXR5cGUHABhhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0NOm1lc3NhZ2UtdHlwZQcACWV4Y2VwdGlvbg86ZXhjZXB0aW9uLXR5cGUHAAlFeGNlcHRpb25UaGlzIGlzIGEgbW9kZWxlZCBleGNlcHRpb24gZXZlbnQgdGhhdCB3b3VsZCBiZSB0aHJvd24gaW4gZGVzZXJpYWxpemVyLj6Gc60=",
"base64"
);

export interface MockEventMessageSourceOptions extends ReadableOptions {
messages: Array<Buffer>;
emitSize: number;
throwError?: Error;
}

export class MockEventMessageSource extends Readable {
private readonly data: Buffer;
private readonly emitSize: number;
private readonly throwError?: Error;
private readCount = 0;
constructor(options: MockEventMessageSourceOptions) {
super(options);
this.data = Buffer.concat(options.messages);
this.emitSize = options.emitSize;
this.throwError = options.throwError;
}

_read() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
if (this.readCount === this.data.length) {
if (this.throwError) {
process.nextTick(function () {
self.emit("error", new Error("Throwing an error!"));
});
return;
} else {
this.push(null);
return;
}
}

const bytesLeft = this.data.length - this.readCount;
const numBytesToSend = Math.min(bytesLeft, this.emitSize);

const chunk = this.data.slice(this.readCount, this.readCount + numBytesToSend);
this.readCount += numBytesToSend;
this.push(chunk);
}
}

describe("getChunkedStream", () => {
it("splits payloads into individual messages", async () => {
const messages = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventStreamCodec } from "@smithy/eventstream-codec";
import { Message } from "@smithy/types";
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";

import { endEventMessage, exception, recordEventMessage, statsEventMessage } from "./fixtures/event.fixture";
import { endEventMessage, exception, recordEventMessage, statsEventMessage } from "./getChunkedStream.spec";
import { getUnmarshalledStream } from "./getUnmarshalledStream";

describe("getUnmarshalledStream", () => {
Expand Down

0 comments on commit b352cc1

Please sign in to comment.