From 2393e5b1db9d320286d52a2f6376300908712b67 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 7 Aug 2024 18:25:42 +0000 Subject: [PATCH] fix(eventstream-serde-universal): mark test code for exclusion --- .changeset/wet-balloons-repair.md | 5 ++ .../MockEventMessageSource.fixture.ts | 49 -------------- .../src/fixtures/event.fixture.ts | 31 --------- .../src/getChunkedStream.spec.ts | 66 ++++++++++++++++++- .../src/getUnmarshalledStream.spec.ts | 2 +- 5 files changed, 70 insertions(+), 83 deletions(-) create mode 100644 .changeset/wet-balloons-repair.md delete mode 100644 packages/eventstream-serde-universal/src/fixtures/MockEventMessageSource.fixture.ts delete mode 100644 packages/eventstream-serde-universal/src/fixtures/event.fixture.ts diff --git a/.changeset/wet-balloons-repair.md b/.changeset/wet-balloons-repair.md new file mode 100644 index 00000000000..db9196cc97b --- /dev/null +++ b/.changeset/wet-balloons-repair.md @@ -0,0 +1,5 @@ +--- +"@smithy/eventstream-serde-universal": patch +--- + +exclude test code from artifact diff --git a/packages/eventstream-serde-universal/src/fixtures/MockEventMessageSource.fixture.ts b/packages/eventstream-serde-universal/src/fixtures/MockEventMessageSource.fixture.ts deleted file mode 100644 index 1e74af14dcc..00000000000 --- a/packages/eventstream-serde-universal/src/fixtures/MockEventMessageSource.fixture.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Readable, ReadableOptions } from "stream"; - -/** - * @internal - */ -export interface MockEventMessageSourceOptions extends ReadableOptions { - messages: Array; - emitSize: number; - throwError?: Error; -} - -/** - * @internal - */ -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); - } -} diff --git a/packages/eventstream-serde-universal/src/fixtures/event.fixture.ts b/packages/eventstream-serde-universal/src/fixtures/event.fixture.ts deleted file mode 100644 index bfe5dd876de..00000000000 --- a/packages/eventstream-serde-universal/src/fixtures/event.fixture.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @internal - */ -export const recordEventMessage = Buffer.from( - "AAAA0AAAAFX31gVLDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB1JlY29yZHMNOmNvbnRlbnQtdHlwZQcAGGFwcGxpY2F0aW9uL29jdGV0LXN0cmVhbTEsRm9vLFdoZW4gbGlmZSBnaXZlcyB5b3UgZm9vLi4uCjIsQmFyLG1ha2UgQmFyIQozLEZpenosU29tZXRpbWVzIHBhaXJlZCB3aXRoLi4uCjQsQnV6eix0aGUgaW5mYW1vdXMgQnV6eiEKzxKeSw==", - "base64" -); - -/** - * @internal - */ -export const statsEventMessage = Buffer.from( - "AAAA0QAAAEM+YpmqDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcABVN0YXRzDTpjb250ZW50LXR5cGUHAAh0ZXh0L3htbDxTdGF0cyB4bWxucz0iIj48Qnl0ZXNTY2FubmVkPjEyNjwvQnl0ZXNTY2FubmVkPjxCeXRlc1Byb2Nlc3NlZD4xMjY8L0J5dGVzUHJvY2Vzc2VkPjxCeXRlc1JldHVybmVkPjEwNzwvQnl0ZXNSZXR1cm5lZD48L1N0YXRzPiJ0pLk=", - "base64" -); - -/** - * @internal - */ -export const endEventMessage = Buffer.from( - "AAAAOAAAACjBxoTUDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAA0VuZM+X05I=", - "base64" -); - -/** - * @internal - */ -export const exception = Buffer.from( - "AAAAtgAAAF8BcW64DTpjb250ZW50LXR5cGUHABhhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0NOm1lc3NhZ2UtdHlwZQcACWV4Y2VwdGlvbg86ZXhjZXB0aW9uLXR5cGUHAAlFeGNlcHRpb25UaGlzIGlzIGEgbW9kZWxlZCBleGNlcHRpb24gZXZlbnQgdGhhdCB3b3VsZCBiZSB0aHJvd24gaW4gZGVzZXJpYWxpemVyLj6Gc60=", - "base64" -); diff --git a/packages/eventstream-serde-universal/src/getChunkedStream.spec.ts b/packages/eventstream-serde-universal/src/getChunkedStream.spec.ts index 31adac9f26f..229a15dce61 100644 --- a/packages/eventstream-serde-universal/src/getChunkedStream.spec.ts +++ b/packages/eventstream-serde-universal/src/getChunkedStream.spec.ts @@ -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; + 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 = []; diff --git a/packages/eventstream-serde-universal/src/getUnmarshalledStream.spec.ts b/packages/eventstream-serde-universal/src/getUnmarshalledStream.spec.ts index 0d37cca2960..3115d500934 100644 --- a/packages/eventstream-serde-universal/src/getUnmarshalledStream.spec.ts +++ b/packages/eventstream-serde-universal/src/getUnmarshalledStream.spec.ts @@ -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", () => {