Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eventstream-serde-universal): mark test code for exclusion #1364

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

This file was deleted.

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
Loading