diff --git a/.changeset/hip-flowers-relax.md b/.changeset/hip-flowers-relax.md new file mode 100644 index 00000000000..873feb92777 --- /dev/null +++ b/.changeset/hip-flowers-relax.md @@ -0,0 +1,5 @@ +--- +"@smithy/snapshot-testing": patch +--- + +add response snapshot generation diff --git a/.changeset/mean-hotels-report.md b/.changeset/mean-hotels-report.md new file mode 100644 index 00000000000..562312b3dc2 --- /dev/null +++ b/.changeset/mean-hotels-report.md @@ -0,0 +1,5 @@ +--- +"@smithy/core": patch +--- + +fix typo in thrown error message diff --git a/api-snapshot/api.json b/api-snapshot/api.json index 96bb2db831a..fd365507d93 100644 --- a/api-snapshot/api.json +++ b/api-snapshot/api.json @@ -489,6 +489,9 @@ "validateSchema": "function, since <=0.0.0" }, "@smithy/snapshot-testing": { - "SnapshotRunner": "function, since <=0.0.1" + "SnapshotRunner": "function, since <=0.0.1", + "customFields": "object, since 1.0.7", + "snapshotTestingProtocolResponseSerializers": "object, since 1.0.7", + "SnapshotProtocol": "function, since 1.0.7" } } \ No newline at end of file diff --git a/packages/core/src/submodules/schema/schemas/NormalizedSchema.ts b/packages/core/src/submodules/schema/schemas/NormalizedSchema.ts index a73ffa997bc..c60e975ae64 100644 --- a/packages/core/src/submodules/schema/schemas/NormalizedSchema.ts +++ b/packages/core/src/submodules/schema/schemas/NormalizedSchema.ts @@ -375,7 +375,7 @@ export class NormalizedSchema implements INormalizedSchema { if (this.isDocumentSchema()) { return member([15 satisfies DocumentSchema, 0], memberName); } - throw new Error(`@smithy/core/schema - ${this.getName(true)} has no no member=${memberName}.`); + throw new Error(`@smithy/core/schema - ${this.getName(true)} has no member=${memberName}.`); } /** diff --git a/packages/snapshot-testing/integ-snapshots/res/EmptyInputOutput.txt b/packages/snapshot-testing/integ-snapshots/res/EmptyInputOutput.txt new file mode 100644 index 00000000000..91bf5520e19 --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/EmptyInputOutput.txt @@ -0,0 +1,50 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/Float16.txt b/packages/snapshot-testing/integ-snapshots/res/Float16.txt new file mode 100644 index 00000000000..d831585057a --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/Float16.txt @@ -0,0 +1,53 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "value": 0 +} + +[actual bytes] +161, 101, 118, 97, 108, 117, 101, 0 + + +[output] +{ + value: (number) 0, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/FractionalSeconds.txt b/packages/snapshot-testing/integ-snapshots/res/FractionalSeconds.txt new file mode 100644 index 00000000000..d7104797897 --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/FractionalSeconds.txt @@ -0,0 +1,56 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "datetime": { + "tag": 1, + "value": 946702799.999 + } +} + +[actual bytes] +161, 104, 100, 97, 116, 101, 116, 105, 109, 101, 193, 251, 65, 204, 54, 196, 231, 255, 223, 59 + + +[output] +{ + datetime: (Date) 12/31/1999, 11:59:59 PM, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/GreetingWithErrors.txt b/packages/snapshot-testing/integ-snapshots/res/GreetingWithErrors.txt new file mode 100644 index 00000000000..2663f56fb5d --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/GreetingWithErrors.txt @@ -0,0 +1,53 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "greeting": "__greeting__" +} + +[actual bytes] +161, 104, 103, 114, 101, 101, 116, 105, 110, 103, 108, 95, 95, 103, 114, 101, 101, 116, 105, 110, 103, 95, 95 + + +[output] +{ + greeting: "__greeting__", + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/NoInputOutput.txt b/packages/snapshot-testing/integ-snapshots/res/NoInputOutput.txt new file mode 100644 index 00000000000..91bf5520e19 --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/NoInputOutput.txt @@ -0,0 +1,50 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/RecursiveShapes.txt b/packages/snapshot-testing/integ-snapshots/res/RecursiveShapes.txt new file mode 100644 index 00000000000..6515f6b184c --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/RecursiveShapes.txt @@ -0,0 +1,81 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "nested": { + "foo": "__foo__", + "nested": { + "bar": "__bar__", + "recursiveMember": { + "foo": "__foo__", + "nested": { + "bar": "__bar__", + "recursiveMember": {} + } + } + } + } +} + +[actual bytes] +161, 102, 110, 101, 115, 116, 101, 100, 162, 99, 102, 111, 111, 103, 95, 95, 102, 111, 111, 95, 95, 102, 110, 101, +115, 116, 101, 100, 162, 99, 98, 97, 114, 103, 95, 95, 98, 97, 114, 95, 95, 111, 114, 101, 99, 117, 114, 115, +105, 118, 101, 77, 101, 109, 98, 101, 114, 162, 99, 102, 111, 111, 103, 95, 95, 102, 111, 111, 95, 95, 102, 110, +101, 115, 116, 101, 100, 162, 99, 98, 97, 114, 103, 95, 95, 98, 97, 114, 95, 95, 111, 114, 101, 99, 117, 114, +115, 105, 118, 101, 77, 101, 109, 98, 101, 114, 160 + + +[output] +{ + nested: { + foo: "__foo__", + nested: { + bar: "__bar__", + recursiveMember: { + foo: "__foo__", + nested: { + bar: "__bar__", + recursiveMember: {} + } + } + } + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/RpcV2CborSparseMaps.txt b/packages/snapshot-testing/integ-snapshots/res/RpcV2CborSparseMaps.txt new file mode 100644 index 00000000000..f9fbcb3269b --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/RpcV2CborSparseMaps.txt @@ -0,0 +1,125 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "sparseStructMap": { + "key1": { + "hi": "__hi__" + }, + "key2": { + "hi": "__hi__" + } + }, + "sparseNumberMap": { + "key1": 0, + "key2": 0 + }, + "sparseBooleanMap": { + "key1": false, + "key2": false + }, + "sparseStringMap": { + "key1": "__value__", + "key2": "__value__" + }, + "sparseSetMap": { + "key1": [ + "__member__", + "__member__", + "__member__" + ], + "key2": [ + "__member__", + "__member__", + "__member__" + ] + } +} + +[actual bytes] +165, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 117, 99, 116, 77, 97, 112, 162, 100, 107, 101, 121, 49, 161, +98, 104, 105, 102, 95, 95, 104, 105, 95, 95, 100, 107, 101, 121, 50, 161, 98, 104, 105, 102, 95, 95, 104, 105, +95, 95, 111, 115, 112, 97, 114, 115, 101, 78, 117, 109, 98, 101, 114, 77, 97, 112, 162, 100, 107, 101, 121, 49, +0, 100, 107, 101, 121, 50, 0, 112, 115, 112, 97, 114, 115, 101, 66, 111, 111, 108, 101, 97, 110, 77, 97, 112, +162, 100, 107, 101, 121, 49, 244, 100, 107, 101, 121, 50, 244, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, +110, 103, 77, 97, 112, 162, 100, 107, 101, 121, 49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, +121, 50, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 108, 115, 112, 97, 114, 115, 101, 83, 101, 116, 77, 97, +112, 162, 100, 107, 101, 121, 49, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, +109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 100, 107, 101, 121, 50, 131, 106, +95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, +109, 101, 109, 98, 101, 114, 95, 95 + + +[output] +{ + sparseStructMap: { + key1: { + hi: "__hi__" + }, + key2: { + hi: "__hi__" + } + }, + sparseNumberMap: { + key1: (number) 0, + key2: (number) 0 + }, + sparseBooleanMap: { + key1: (boolean) false, + key2: (boolean) false + }, + sparseStringMap: { + key1: "__value__", + key2: "__value__" + }, + sparseSetMap: { + key1: [ + "__member__", + "__member__", + "__member__" + ], + key2: [ + "__member__", + "__member__", + "__member__" + ] + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/SimpleScalarProperties.txt b/packages/snapshot-testing/integ-snapshots/res/SimpleScalarProperties.txt new file mode 100644 index 00000000000..b835b26050b --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/SimpleScalarProperties.txt @@ -0,0 +1,85 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "trueBooleanValue": false, + "falseBooleanValue": false, + "byteValue": 0, + "doubleValue": 0, + "floatValue": 0, + "integerValue": 0, + "longValue": 0, + "shortValue": 0, + "stringValue": "__stringValue__", + "blobValue": { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + } +} + +[actual bytes] +170, 112, 116, 114, 117, 101, 66, 111, 111, 108, 101, 97, 110, 86, 97, 108, 117, 101, 244, 113, 102, 97, 108, 115, +101, 66, 111, 111, 108, 101, 97, 110, 86, 97, 108, 117, 101, 244, 105, 98, 121, 116, 101, 86, 97, 108, 117, 101, +0, 107, 100, 111, 117, 98, 108, 101, 86, 97, 108, 117, 101, 0, 106, 102, 108, 111, 97, 116, 86, 97, 108, 117, +101, 0, 108, 105, 110, 116, 101, 103, 101, 114, 86, 97, 108, 117, 101, 0, 105, 108, 111, 110, 103, 86, 97, 108, +117, 101, 0, 106, 115, 104, 111, 114, 116, 86, 97, 108, 117, 101, 0, 107, 115, 116, 114, 105, 110, 103, 86, 97, +108, 117, 101, 111, 95, 95, 115, 116, 114, 105, 110, 103, 86, 97, 108, 117, 101, 95, 95, 105, 98, 108, 111, 98, +86, 97, 108, 117, 101, 68, 1, 0, 0, 1 + + +[output] +{ + trueBooleanValue: (boolean) false, + falseBooleanValue: (boolean) false, + byteValue: (number) 0, + doubleValue: (number) 0, + floatValue: (number) 0, + integerValue: (number) 0, + longValue: (number) 0, + shortValue: (number) 0, + stringValue: "__stringValue__", + blobValue: (Uint8Array) bytes[1, 0, 0, 1], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/integ-snapshots/res/SparseNullsOperation.txt b/packages/snapshot-testing/integ-snapshots/res/SparseNullsOperation.txt new file mode 100644 index 00000000000..981dccb04d7 --- /dev/null +++ b/packages/snapshot-testing/integ-snapshots/res/SparseNullsOperation.txt @@ -0,0 +1,73 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +[output] +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "sparseStringList": [ + "__member__", + "__member__", + "__member__" + ], + "sparseStringMap": { + "key1": "__value__", + "key2": "__value__" + } +} + +[actual bytes] +162, 112, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, 110, 103, 76, 105, 115, 116, 131, 106, 95, 95, 109, 101, +109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, +101, 114, 95, 95, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, 110, 103, 77, 97, 112, 162, 100, 107, 101, +121, 49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, 121, 50, 105, 95, 95, 118, 97, 108, 117, +101, 95, 95 + + +[output] +{ + sparseStringList: [ + "__member__", + "__member__", + "__member__" + ], + sparseStringMap: { + key1: "__value__", + key2: "__value__" + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/packages/snapshot-testing/src/SnapshotRequestHandler.ts b/packages/snapshot-testing/src/SnapshotRequestHandler.ts index 8fc8a81d8b0..03d5bc04b33 100644 --- a/packages/snapshot-testing/src/SnapshotRequestHandler.ts +++ b/packages/snapshot-testing/src/SnapshotRequestHandler.ts @@ -19,6 +19,11 @@ export interface SnapshotRequestHandlerOptions { * The serialized request will be pushed to the logger's trace method. */ logger?: Logger; + + /** + * Optional response to use. + */ + response?: IHttpResponse; } /** @@ -43,7 +48,11 @@ export class SnapshotRequestHandler implements HttpHandler> { - const { logger } = this.config; + const { logger, response } = this.config; + + if (response) { + return { response }; + } const [client, [, namespace, name, traits, input, output], command] = [ handlerOptions[Symbol.for("$client")], @@ -65,9 +74,9 @@ export class SnapshotRequestHandler implements HttpHandler( + key: K, + value: SnapshotRequestHandlerOptions[K] ): void { this.config[key] = value; } diff --git a/packages/snapshot-testing/src/SnapshotRunner.ts b/packages/snapshot-testing/src/SnapshotRunner.ts index 9551e79748a..0664f6f416a 100644 --- a/packages/snapshot-testing/src/SnapshotRunner.ts +++ b/packages/snapshot-testing/src/SnapshotRunner.ts @@ -1,17 +1,12 @@ import { NormalizedSchema } from "@smithy/core/schema"; -import { HttpRequest } from "@smithy/protocol-http"; -import type { - BuildMiddleware, - Client, - Command, - FinalizeRequestMiddleware, - Logger, - StaticOperationSchema, -} from "@smithy/types"; +import type { Client, Command, HttpResponse as IHttpResponse, Logger, StaticOperationSchema } from "@smithy/types"; import { readFileSync } from "fs"; import { accessSync, constants, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; +import { snapshotTestingProtocolResponseSerializers } from "./protocols/index"; +import { serializeDocument } from "./serializers/serializeDocument"; +import { serializeHttpResponse } from "./serializers/serializeHttpResponse"; import { RequestSnapshotCompleted } from "./snapshot-testing-types"; import { SnapshotRequestHandler } from "./SnapshotRequestHandler"; import { createFromSchema } from "./structure/createFromSchema"; @@ -109,10 +104,11 @@ export class SnapshotRunner { const promises = [] as Promise[]; + // requests for (const [schema, CommandCtor] of schemas) { const operationName = CommandCtor.name.replace(/Command$/, ""); - const testCaseExec = testCase(operationName, async () => { + const testCaseExec = testCase(operationName + " (request)", async () => { let buf = ``; const logger = { ...console, @@ -158,6 +154,80 @@ export class SnapshotRunner { promises.push(Promise.resolve(testCaseExec)); } + // responses + for (const [schema, CommandCtor] of schemas) { + const operationName = CommandCtor.name.replace(/Command$/, ""); + + const testCaseExec = testCase(operationName + " (response)", async () => { + let buf = ``; + const logger = { + ...console, + trace(msg: string) { + buf += msg; + }, + }; + + const client = this.initClient(Client, { endpoint: "https://localhost", logger }); + const protocolId = client.config.protocol.getShapeId(); + + for (const options of [{ mode: "min" }, { mode: "max" }] as const) { + if (options.mode === "min") { + logger.trace("=".repeat(24) + ` minimal response ` + "=".repeat(24)); + } else { + logger.trace("=".repeat(24) + ` w/ optional fields ` + "=".repeat(24)); + } + logger.trace("\n"); + + const snapshotProtocol = snapshotTestingProtocolResponseSerializers[protocolId]; + if (!snapshotProtocol) { + throw new Error(`No response serializer found for protocol: ${protocolId}`); + } + snapshotProtocol.setSerdeContext(client.config); + + // copies to allow two types of serializers to read the response stream. + const [r1, r2] = [ + await snapshotProtocol.serializeResponse(schema, createFromSchema(schema[5], undefined, options)), + await snapshotProtocol.serializeResponse(schema, createFromSchema(schema[5], undefined, options)), + ]; + + const serialization = await serializeHttpResponse(r1); + logger.trace(serialization); + + const command = new CommandCtor(createFromSchema(schema[4 /*input*/])); + client.config.requestHandler = new SnapshotRequestHandler({ + response: r2, + }); + const output = await client.send(command); + const outputSerialization = await serializeDocument(output); + + logger.trace("\n\n--- [output object] ---\n"); + logger.trace(outputSerialization); + logger.trace("\n\n"); + } + + const snapshotPath = join(snapshotDirPath, "res", operationName + ".txt"); + const containerFolder = dirname(snapshotPath); + if (!existsSync(containerFolder)) { + mkdirSync(containerFolder, { recursive: true }); + } + + if (mode === "compare") { + const canonical = readFileSync(snapshotPath, "utf-8"); + if (assertions) { + assertions(operationName, canonical, buf); + } else { + if (canonical !== buf) { + throw new Error(`Deserialization for ${CommandCtor.name} does not match snapshot on disk.`); + } + } + } else { + writeFileSync(snapshotPath, buf, "utf-8"); + } + }); + + promises.push(Promise.resolve(testCaseExec)); + } + return Promise.all(promises).then(() => {}); } @@ -174,18 +244,7 @@ export class SnapshotRunner { CommandCtor: $CommandCtor; endpoint?: string; }) { - const client = new Client({ - region: "us-east-1", - credentials: { - accessKeyId: "MOCK_ak", - secretAccessKey: "MOCK_sak", - }, - apiKey: { apiKey: "MOCK_api_key" }, - endpoint, - requestHandler: new SnapshotRequestHandler({ - logger, - }), - }); + const client = this.initClient(Client, { endpoint, logger }); const [, namespace, name, traits, input, output] = schema; const command = new CommandCtor(createFromSchema(input)); @@ -203,7 +262,7 @@ export class SnapshotRunner { [Symbol.for("$client")]: client, [Symbol.for("$command")]: command, }; - await client.send(command, snapshotMetadata).catch((e) => { + await client.send(command, snapshotMetadata).catch((e: any) => { switch (e.name) { case "EndpointError": return this.executeCommand({ @@ -219,6 +278,25 @@ export class SnapshotRunner { }); } + private initClient( + Client: any, + { endpoint, logger, response }: { endpoint?: string; logger?: Logger; response?: IHttpResponse } + ): any { + return new Client({ + region: "us-east-1", + credentials: { + accessKeyId: "MOCK_ak", + secretAccessKey: "MOCK_sak", + }, + apiKey: { apiKey: "MOCK_api_key" }, + endpoint, + requestHandler: new SnapshotRequestHandler({ + logger, + response, + }), + }); + } + private getEventStreamStaticSignatureMiddleware = (next: any, context: any) => async (args: any) => { context.__staticSignature = true; return next(args); diff --git a/packages/snapshot-testing/src/index.ts b/packages/snapshot-testing/src/index.ts index 2e57d80609c..dd016d58d07 100644 --- a/packages/snapshot-testing/src/index.ts +++ b/packages/snapshot-testing/src/index.ts @@ -1,2 +1,15 @@ export { SnapshotRunner } from "./SnapshotRunner"; export { customFields } from "./structure/createFromSchema"; + +/** + * Extend this to create additional snapshot response serializers. + * + * @internal + */ +export { SnapshotProtocol } from "./protocols/SnapshotProtocol"; + +/** + * Add additional SnapshotProtocol to this object, key by protocol ShapeId. + * @internal + */ +export { snapshotTestingProtocolResponseSerializers } from "./protocols/index"; diff --git a/packages/snapshot-testing/src/protocols/SmithyRpcV2CborSnapshotProtocol.ts b/packages/snapshot-testing/src/protocols/SmithyRpcV2CborSnapshotProtocol.ts new file mode 100644 index 00000000000..f6465e16319 --- /dev/null +++ b/packages/snapshot-testing/src/protocols/SmithyRpcV2CborSnapshotProtocol.ts @@ -0,0 +1,54 @@ +import { CborCodec } from "@smithy/core/cbor"; +import { NormalizedSchema } from "@smithy/core/schema"; +import type { HttpResponse, StaticOperationSchema } from "@smithy/types"; + +import type { SnapshotServerProtocol } from "../snapshot-testing-types"; +import { SnapshotProtocol } from "./SnapshotProtocol"; + +/** + * @internal + */ +export class SmithyRpcV2CborSnapshotProtocol extends SnapshotProtocol implements SnapshotServerProtocol { + private codec = new CborCodec(); + private serializer = this.codec.createSerializer(); + private deserializer = this.codec.createDeserializer(); + + public getShapeId(): string { + return "smithy.protocols#rpcv2Cbor"; + } + + public async serializeResponse(operationSchema: StaticOperationSchema, output: any): Promise { + const $output = NormalizedSchema.of(operationSchema[5]); + const eventStreamMember = $output.getEventStreamMember(); + + const response: HttpResponse = { + statusCode: 200, + headers: { + "smithy-protocol": "rpc-v2-cbor", + "content-type": "application/cbor", + }, + }; + + if (eventStreamMember) { + const eventStreamSerde = this.getEventStreamSerde(this.serializer, this.deserializer); + + if (output[eventStreamMember]?.[Symbol.asyncIterator]) { + response.body = await eventStreamSerde.serializeEventStream({ + eventStream: output[eventStreamMember], + requestSchema: $output, + }); + } else { + response.body = { + async *[Symbol.asyncIterator]() {}, + }; + } + } else { + const { serializer } = this; + serializer.write($output, output); + // refrain from wrapping in Readable so the snapshot can use object view on the bytes. + response.body = serializer.flush(); + } + + return response; + } +} diff --git a/packages/snapshot-testing/src/protocols/SnapshotProtocol.ts b/packages/snapshot-testing/src/protocols/SnapshotProtocol.ts new file mode 100644 index 00000000000..c4011f56f78 --- /dev/null +++ b/packages/snapshot-testing/src/protocols/SnapshotProtocol.ts @@ -0,0 +1,41 @@ +import { EventStreamSerde } from "@smithy/core/event-streams"; +import { SerdeContext } from "@smithy/core/protocols"; +import type { + $ShapeDeserializer, + $ShapeSerializer, + EventStreamMarshaller, + EventStreamSerdeContext, + HttpResponse, + StaticOperationSchema, +} from "@smithy/types"; + +import type { SnapshotServerProtocol } from "../snapshot-testing-types"; + +/** + * @internal + */ +export abstract class SnapshotProtocol extends SerdeContext implements SnapshotServerProtocol { + public abstract getShapeId(): string; + + public abstract serializeResponse( + operationSchema: StaticOperationSchema, + output: Output + ): Promise; + + protected getEventStreamSerde(serializer: $ShapeSerializer, deserializer: $ShapeDeserializer) { + return new EventStreamSerde({ + marshaller: this.getEventStreamMarshaller(), + serializer, + deserializer, + defaultContentType: "application/cbor", + }); + } + + protected getEventStreamMarshaller(): EventStreamMarshaller { + const context = this.serdeContext as unknown as EventStreamSerdeContext; + if (!context.eventStreamMarshaller) { + throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext."); + } + return context.eventStreamMarshaller; + } +} diff --git a/packages/snapshot-testing/src/protocols/index.ts b/packages/snapshot-testing/src/protocols/index.ts new file mode 100644 index 00000000000..2c72ba1cada --- /dev/null +++ b/packages/snapshot-testing/src/protocols/index.ts @@ -0,0 +1,10 @@ +import { SmithyRpcV2CborSnapshotProtocol } from "./SmithyRpcV2CborSnapshotProtocol"; + +const smithyRpcV2CborSnapshotProtocol = new SmithyRpcV2CborSnapshotProtocol(); + +/** + * @internal + */ +export const snapshotTestingProtocolResponseSerializers = { + [smithyRpcV2CborSnapshotProtocol.getShapeId()]: smithyRpcV2CborSnapshotProtocol, +}; diff --git a/packages/snapshot-testing/src/serializers/ContentTypeDetection.ts b/packages/snapshot-testing/src/serializers/ContentTypeDetection.ts index 1e0755ef72e..b8c7c5eef82 100644 --- a/packages/snapshot-testing/src/serializers/ContentTypeDetection.ts +++ b/packages/snapshot-testing/src/serializers/ContentTypeDetection.ts @@ -4,6 +4,9 @@ import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; import { serializeBytes } from "./serializeBytes"; +/** + * @internal + */ export class ContentTypeDetection { protected r!: { headers: HeaderBag; diff --git a/packages/snapshot-testing/src/serializers/SnapshotEventStreamSerializer.ts b/packages/snapshot-testing/src/serializers/SnapshotEventStreamSerializer.ts index 1cec69969c3..49e9ec0b41a 100644 --- a/packages/snapshot-testing/src/serializers/SnapshotEventStreamSerializer.ts +++ b/packages/snapshot-testing/src/serializers/SnapshotEventStreamSerializer.ts @@ -3,7 +3,11 @@ import { toHex } from "@smithy/util-hex-encoding"; import { toUtf8 } from "@smithy/util-utf8"; import { ContentTypeDetection } from "./ContentTypeDetection"; +import { serializeDate } from "./serializeDate"; +/** + * @internal + */ export class SnapshotEventStreamSerializer extends ContentTypeDetection { private headers: Message["headers"] = {}; @@ -175,18 +179,7 @@ function serializeEventHeaders(headers: Message["headers"]): string { if (type === "string") { b += `${k}: ${value}\n`; } else if (value instanceof Date) { - b += `${k}: ${value.toLocaleString("en-US", { - timeZone: "America/Los_Angeles", - weekday: "short", - year: "numeric", - month: "short", - day: "numeric", - hour: "numeric", - minute: "2-digit", - second: "2-digit", - timeZoneName: "long", - hour12: false, - })} (${type})\n`; + b += `${k}: ${serializeDate(value)} (${type})\n`; } else { b += `${k}: ${value} (${type})\n`; } diff --git a/packages/snapshot-testing/src/serializers/SnapshotPayloadSerializer.ts b/packages/snapshot-testing/src/serializers/SnapshotPayloadSerializer.ts index 2df1ecf17b0..bbf77c902d6 100644 --- a/packages/snapshot-testing/src/serializers/SnapshotPayloadSerializer.ts +++ b/packages/snapshot-testing/src/serializers/SnapshotPayloadSerializer.ts @@ -5,6 +5,9 @@ import type { PayloadWithHeaders } from "../snapshot-testing-types"; import { ContentTypeDetection } from "./ContentTypeDetection"; import { SnapshotEventStreamSerializer } from "./SnapshotEventStreamSerializer"; +/** + * @internal + */ export class SnapshotPayloadSerializer extends ContentTypeDetection { public constructor(protected r: PayloadWithHeaders) { super(); diff --git a/packages/snapshot-testing/src/serializers/serializeBytes.ts b/packages/snapshot-testing/src/serializers/serializeBytes.ts index 1e18e6430dc..e727eec64b1 100644 --- a/packages/snapshot-testing/src/serializers/serializeBytes.ts +++ b/packages/snapshot-testing/src/serializers/serializeBytes.ts @@ -11,6 +11,9 @@ export function serializeBytes(bytes: Uint8Array): string { return `${objectString}\n\n[actual bytes]\n${byteList}`; } +/** + * @internal + */ export function bytesToString(bytes: Uint8Array) { const items = Array.from(bytes).map((b) => String(b)); const lines = []; @@ -20,6 +23,9 @@ export function bytesToString(bytes: Uint8Array) { return lines.join(",\n"); } +/** + * @internal + */ export function debugBytes(bytes: Uint8Array): string { const object = cbor.deserialize(bytes); diff --git a/packages/snapshot-testing/src/serializers/serializeDate.ts b/packages/snapshot-testing/src/serializers/serializeDate.ts new file mode 100644 index 00000000000..527beacbff1 --- /dev/null +++ b/packages/snapshot-testing/src/serializers/serializeDate.ts @@ -0,0 +1,13 @@ +export const serializeDate = (d: Date) => + d.toLocaleString("en-US", { + timeZone: "America/Los_Angeles", + weekday: "short", + year: "numeric", + month: "short", + day: "numeric", + hour: "numeric", + minute: "2-digit", + second: "2-digit", + timeZoneName: "long", + hour12: false, + }); diff --git a/packages/snapshot-testing/src/serializers/serializeDocument.ts b/packages/snapshot-testing/src/serializers/serializeDocument.ts new file mode 100644 index 00000000000..4b54bc5656c --- /dev/null +++ b/packages/snapshot-testing/src/serializers/serializeDocument.ts @@ -0,0 +1,56 @@ +import { serializeDate } from "./serializeDate"; + +/** + * @internal + */ +export async function serializeDocument(doc: any, indent = 0): Promise { + const spaces = " ".repeat(indent); + const type = doc instanceof Date ? "Date" : doc instanceof Uint8Array ? "Uint8Array" : typeof doc; + + if (doc === null) { + return `${spaces}(null)`; + } + if (doc === undefined) { + return `${spaces}(undefined)`; + } + if (doc instanceof Date) { + return `${spaces}(Date) ${serializeDate(doc)}`; + } + if (doc instanceof Uint8Array) { + return `${spaces}(Uint8Array) bytes[${Array.from(doc).join(", ")}]`; + } + if (typeof doc !== "object") { + if (type === "string") { + return `${spaces}"${doc}"`; + } + return `${spaces}(${type}) ${doc}`; + } + + if (doc[Symbol.asyncIterator]) { + const values = []; + for await (const value of doc) { + values.push(await serializeDocument(value, indent + 2)); + } + if (values.length === 0) { + return `${spaces}async_it[]`; + } + return `${spaces}async_it[\n${values.join(",\n")}\n${spaces}]`; + } + + if (Array.isArray(doc)) { + if (doc.length === 0) { + return `${spaces}[]`; + } + const serialized = await Promise.all(doc.map((v) => serializeDocument(v, indent + 2))); + return `${spaces}[\n${serialized.join(",\n")}\n${spaces}]`; + } + + const keys = Object.keys(doc); + if (keys.length === 0) { + return `${spaces}{}`; + } + const serialized = await Promise.all( + keys.map(async (k) => `${" ".repeat(indent + 2)}${k}: ${(await serializeDocument(doc[k], indent + 2)).trim()}`) + ); + return `${spaces}{\n${serialized.join(",\n")}\n${spaces}}`; +} diff --git a/packages/snapshot-testing/src/serializers/serializeHttpRequest.ts b/packages/snapshot-testing/src/serializers/serializeHttpRequest.ts index 55c5284ede7..7f17cbbac7e 100644 --- a/packages/snapshot-testing/src/serializers/serializeHttpRequest.ts +++ b/packages/snapshot-testing/src/serializers/serializeHttpRequest.ts @@ -5,6 +5,8 @@ import { SnapshotPayloadSerializer } from "./SnapshotPayloadSerializer"; /** * Serialize an http request to string for snapshotting. * @param request + * + * @internal */ export async function serializeHttpRequest(request: IHttpRequest): Promise { const { method, protocol, hostname, port, path, query, headers, username, password, fragment, body } = request; diff --git a/packages/snapshot-testing/src/serializers/serializeHttpResponse.ts b/packages/snapshot-testing/src/serializers/serializeHttpResponse.ts new file mode 100644 index 00000000000..c402def1409 --- /dev/null +++ b/packages/snapshot-testing/src/serializers/serializeHttpResponse.ts @@ -0,0 +1,24 @@ +import type { HttpResponse } from "@smithy/types"; + +import { SnapshotPayloadSerializer } from "./SnapshotPayloadSerializer"; + +/** + * @internal + */ +export async function serializeHttpResponse(r: HttpResponse): Promise { + const { statusCode, headers } = r; + + let headerLines = ``; + for (const [k, v] of Object.entries(headers ?? {})) { + headerLines += `${k}: ${v}\n`; + } + + const [bodyAnnotation, bodySnapshot] = await new SnapshotPayloadSerializer(r).toStringAsync(); + + return `[status] ${statusCode} + +${headerLines} +${bodyAnnotation} +${bodySnapshot} +`; +} diff --git a/packages/snapshot-testing/src/snapshot-testing-types.ts b/packages/snapshot-testing/src/snapshot-testing-types.ts index 241c239245b..761fa5b42b7 100644 --- a/packages/snapshot-testing/src/snapshot-testing-types.ts +++ b/packages/snapshot-testing/src/snapshot-testing-types.ts @@ -1,4 +1,9 @@ -import type { HttpRequest as IHttpRequest, HttpResponse as IHttpResponse } from "@smithy/types"; +import type { + HttpRequest as IHttpRequest, + HttpResponse, + HttpResponse as IHttpResponse, + StaticOperationSchema, +} from "@smithy/types"; /** * @internal @@ -11,3 +16,17 @@ export type PayloadWithHeaders = Pick | Pick( + operationSchema: StaticOperationSchema, + output: Output + ): Promise; +} diff --git a/packages/snapshot-testing/src/structure/createFromSchema.ts b/packages/snapshot-testing/src/structure/createFromSchema.ts index 4903fbd7af1..47709999691 100644 --- a/packages/snapshot-testing/src/structure/createFromSchema.ts +++ b/packages/snapshot-testing/src/structure/createFromSchema.ts @@ -1,6 +1,6 @@ import { NormalizedSchema } from "@smithy/core/schema"; import { NumericValue } from "@smithy/core/serde"; -import type { $SchemaRef } from "@smithy/types"; +import type { $SchemaRef, StaticStructureSchema } from "@smithy/types"; /** * Creates a static value for a given schema. @@ -9,8 +9,11 @@ import type { $SchemaRef } from "@smithy/types"; * * @param schema - for which to generate an object. * @param path - to cut off recursive schema at a certain depth. + * @param options + * @param options.mode - 'min' or 'max' for generating optional members. */ -export function createFromSchema(schema: $SchemaRef, path = ""): any { +export function createFromSchema(schema: $SchemaRef, path = "", options: { mode?: "min" | "max" } = {}): any { + const { mode = "max" } = options; const $ = NormalizedSchema.of(schema); const memberName = $.isMemberSchema() ? $.getMemberName() : "____"; @@ -46,9 +49,9 @@ export function createFromSchema(schema: $SchemaRef, path = ""): any { return map; } const $v = $.getValueSchema(); - map.key1 = createFromSchema($v, path + "$k1"); - map.key2 = createFromSchema($v, path + "$k2"); - map.key2 = createFromSchema($v, path + "$k3"); + map.key1 = createFromSchema($v, path + "$k1", options); + map.key2 = createFromSchema($v, path + "$k2", options); + map.key2 = createFromSchema($v, path + "$k3", options); return map; } else if ($.isListSchema()) { const list = [] as any; @@ -57,13 +60,14 @@ export function createFromSchema(schema: $SchemaRef, path = ""): any { } const $v = $.getValueSchema(); list.push( - createFromSchema($v, path + "$l1"), - createFromSchema($v, path + "$l2"), - createFromSchema($v, path + "$l3") + createFromSchema($v, path + "$l1", options), + createFromSchema($v, path + "$l2", options), + createFromSchema($v, path + "$l3", options) ); return list; } else if ($.isStructSchema()) { const isUnion = $.isUnionSchema(); + const requiredMembers = ($.getSchema() as StaticStructureSchema)[6] ?? 0; const isEventStream = isUnion && $.isStreaming(); const struct = {} as any; if (isEventStream) { @@ -71,7 +75,7 @@ export function createFromSchema(schema: $SchemaRef, path = ""): any { async *[Symbol.asyncIterator]() { for (const [memberName, $member] of $.structIterator()) { yield { - [memberName]: createFromSchema($member, path), + [memberName]: createFromSchema($member, path, options), }; } }, @@ -88,8 +92,11 @@ export function createFromSchema(schema: $SchemaRef, path = ""): any { let i = 0; for (const [memberName, $member] of $.structIterator()) { + if (i >= requiredMembers && mode === "min") { + break; + } if (!isUnion || i++ === unionMemberSelector) { - struct[memberName] = createFromSchema($member, path); + struct[memberName] = createFromSchema($member, path, options); if (isUnion) { break; } diff --git a/private/my-local-model-schema/test/snapshots/res/CamelCaseOperation.txt b/private/my-local-model-schema/test/snapshots/res/CamelCaseOperation.txt new file mode 100644 index 00000000000..6f4ab543c70 --- /dev/null +++ b/private/my-local-model-schema/test/snapshots/res/CamelCaseOperation.txt @@ -0,0 +1,88 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "token": "__token__", + "results": [ + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + } + ] +} + +[actual bytes] +162, 101, 116, 111, 107, 101, 110, 105, 95, 95, 116, 111, 107, 101, 110, 95, 95, 103, 114, 101, 115, 117, 108, 116, +115, 131, 68, 1, 0, 0, 1, 68, 1, 0, 0, 1, 68, 1, 0, 0, 1 + + +--- [output object] --- +{ + token: "__token__", + results: [ + (Uint8Array) bytes[1, 0, 0, 1], + (Uint8Array) bytes[1, 0, 0, 1], + (Uint8Array) bytes[1, 0, 0, 1] + ], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/my-local-model-schema/test/snapshots/res/GetNumbers.txt b/private/my-local-model-schema/test/snapshots/res/GetNumbers.txt new file mode 100644 index 00000000000..4dca55c9daf --- /dev/null +++ b/private/my-local-model-schema/test/snapshots/res/GetNumbers.txt @@ -0,0 +1,76 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "bigDecimal": { + "string": "9876543210.0123456789", + "type": "bigDecimal" + }, + "bigInteger": 1000001, + "numbers": [ + 0, + 0, + 0 + ], + "nextToken": "__nextToken__" +} + +[actual bytes] +164, 106, 98, 105, 103, 68, 101, 99, 105, 109, 97, 108, 196, 130, 41, 194, 73, 5, 90, 165, 77, 54, 159, 210, +53, 21, 106, 98, 105, 103, 73, 110, 116, 101, 103, 101, 114, 26, 0, 15, 66, 65, 103, 110, 117, 109, 98, 101, +114, 115, 131, 0, 0, 0, 105, 110, 101, 120, 116, 84, 111, 107, 101, 110, 109, 95, 95, 110, 101, 120, 116, 84, +111, 107, 101, 110, 95, 95 + + +--- [output object] --- +{ + bigDecimal: { + string: "9876543210.0123456789", + type: "bigDecimal" + }, + bigInteger: (number) 1000001, + numbers: [ + (number) 0, + (number) 0, + (number) 0 + ], + nextToken: "__nextToken__", + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/my-local-model-schema/test/snapshots/res/HttpLabelCommand.txt b/private/my-local-model-schema/test/snapshots/res/HttpLabelCommand.txt new file mode 100644 index 00000000000..0a037cbe9d7 --- /dev/null +++ b/private/my-local-model-schema/test/snapshots/res/HttpLabelCommand.txt @@ -0,0 +1,50 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/my-local-model-schema/test/snapshots/res/TradeEventStream.txt b/private/my-local-model-schema/test/snapshots/res/TradeEventStream.txt new file mode 100644 index 00000000000..e4f858614ac --- /dev/null +++ b/private/my-local-model-schema/test/snapshots/res/TradeEventStream.txt @@ -0,0 +1,115 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[async_iterable (Object)] + + + + +--- [output object] --- +{ + eventStream: async_it[], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[async_iterable (Readable)] + +[chunk (event-stream object view)] + [total-size] 122 [header-size] 75 [prelude-crc] 927907615 +:event-type: alpha +:message-type: event +:content-type: application/cbor + +[cbor object view] +{ + "id": "__id__", + "timestamp": { + "tag": 1, + "value": 946702799.999 + } +} + +[actual bytes] +162, 98, 105, 100, 102, 95, 95, 105, 100, 95, 95, 105, 116, 105, 109, 101, 115, 116, 97, 109, 112, 193, 251, 65, +204, 54, 196, 231, 255, 223, 59 + +[message-crc] 2274737008 +============================================================ + +[chunk (event-stream object view)] + [total-size] 91 [header-size] 74 [prelude-crc] 3169356093 +:event-type: beta +:message-type: event +:content-type: application/cbor + +[cbor object view] +{} + +[actual bytes] +160 + +[message-crc] 3285270063 +============================================================ + +[chunk (event-stream object view)] + [total-size] 92 [header-size] 75 [prelude-crc] 2043635131 +:event-type: gamma +:message-type: event +:content-type: application/cbor + +[cbor object view] +{} + +[actual bytes] +160 + +[message-crc] 2477278713 +============================================================ + +[chunk (b64)] +Cg== + + + +--- [output object] --- +{ + eventStream: async_it[ + { + alpha: { + id: "__id__", + timestamp: (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time + } + }, + { + beta: {} + }, + { + gamma: {} + } + ], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/EmptyInputOutput.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/EmptyInputOutput.txt new file mode 100644 index 00000000000..0a037cbe9d7 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/EmptyInputOutput.txt @@ -0,0 +1,50 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/Float16.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/Float16.txt new file mode 100644 index 00000000000..dafd4839085 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/Float16.txt @@ -0,0 +1,53 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "value": 0 +} + +[actual bytes] +161, 101, 118, 97, 108, 117, 101, 0 + + +--- [output object] --- +{ + value: (number) 0, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/FractionalSeconds.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/FractionalSeconds.txt new file mode 100644 index 00000000000..02d393d56a7 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/FractionalSeconds.txt @@ -0,0 +1,56 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "datetime": { + "tag": 1, + "value": 946702799.999 + } +} + +[actual bytes] +161, 104, 100, 97, 116, 101, 116, 105, 109, 101, 193, 251, 65, 204, 54, 196, 231, 255, 223, 59 + + +--- [output object] --- +{ + datetime: (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/GreetingWithErrors.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/GreetingWithErrors.txt new file mode 100644 index 00000000000..8ae7b8bbf6d --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/GreetingWithErrors.txt @@ -0,0 +1,53 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "greeting": "__greeting__" +} + +[actual bytes] +161, 104, 103, 114, 101, 101, 116, 105, 110, 103, 108, 95, 95, 103, 114, 101, 101, 116, 105, 110, 103, 95, 95 + + +--- [output object] --- +{ + greeting: "__greeting__", + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/NoInputOutput.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/NoInputOutput.txt new file mode 100644 index 00000000000..0a037cbe9d7 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/NoInputOutput.txt @@ -0,0 +1,50 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OperationWithDefaults.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OperationWithDefaults.txt new file mode 100644 index 00000000000..9091423a378 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OperationWithDefaults.txt @@ -0,0 +1,148 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "defaultString": "__defaultString__", + "defaultBoolean": false, + "defaultList": [ + "__member__", + "__member__", + "__member__" + ], + "defaultTimestamp": { + "tag": 1, + "value": 946702799.999 + }, + "defaultBlob": { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + "defaultByte": 0, + "defaultShort": 0, + "defaultInteger": 0, + "defaultLong": 0, + "defaultFloat": 0, + "defaultDouble": 0, + "defaultMap": { + "key1": "__value__", + "key2": "__value__" + }, + "defaultEnum": "__defaultEnum__", + "defaultIntEnum": 0, + "emptyString": "__emptyString__", + "falseBoolean": false, + "emptyBlob": { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + "zeroByte": 0, + "zeroShort": 0, + "zeroInteger": 0, + "zeroLong": 0, + "zeroFloat": 0, + "zeroDouble": 0 +} + +[actual bytes] +183, 109, 100, 101, 102, 97, 117, 108, 116, 83, 116, 114, 105, 110, 103, 113, 95, 95, 100, 101, 102, 97, 117, 108, +116, 83, 116, 114, 105, 110, 103, 95, 95, 110, 100, 101, 102, 97, 117, 108, 116, 66, 111, 111, 108, 101, 97, 110, +244, 107, 100, 101, 102, 97, 117, 108, 116, 76, 105, 115, 116, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, +95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 112, +100, 101, 102, 97, 117, 108, 116, 84, 105, 109, 101, 115, 116, 97, 109, 112, 193, 251, 65, 204, 54, 196, 231, 255, +223, 59, 107, 100, 101, 102, 97, 117, 108, 116, 66, 108, 111, 98, 68, 1, 0, 0, 1, 107, 100, 101, 102, 97, +117, 108, 116, 66, 121, 116, 101, 0, 108, 100, 101, 102, 97, 117, 108, 116, 83, 104, 111, 114, 116, 0, 110, 100, +101, 102, 97, 117, 108, 116, 73, 110, 116, 101, 103, 101, 114, 0, 107, 100, 101, 102, 97, 117, 108, 116, 76, 111, +110, 103, 0, 108, 100, 101, 102, 97, 117, 108, 116, 70, 108, 111, 97, 116, 0, 109, 100, 101, 102, 97, 117, 108, +116, 68, 111, 117, 98, 108, 101, 0, 106, 100, 101, 102, 97, 117, 108, 116, 77, 97, 112, 162, 100, 107, 101, 121, +49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, 121, 50, 105, 95, 95, 118, 97, 108, 117, 101, +95, 95, 107, 100, 101, 102, 97, 117, 108, 116, 69, 110, 117, 109, 111, 95, 95, 100, 101, 102, 97, 117, 108, 116, +69, 110, 117, 109, 95, 95, 110, 100, 101, 102, 97, 117, 108, 116, 73, 110, 116, 69, 110, 117, 109, 0, 107, 101, +109, 112, 116, 121, 83, 116, 114, 105, 110, 103, 111, 95, 95, 101, 109, 112, 116, 121, 83, 116, 114, 105, 110, 103, +95, 95, 108, 102, 97, 108, 115, 101, 66, 111, 111, 108, 101, 97, 110, 244, 105, 101, 109, 112, 116, 121, 66, 108, +111, 98, 68, 1, 0, 0, 1, 104, 122, 101, 114, 111, 66, 121, 116, 101, 0, 105, 122, 101, 114, 111, 83, 104, +111, 114, 116, 0, 107, 122, 101, 114, 111, 73, 110, 116, 101, 103, 101, 114, 0, 104, 122, 101, 114, 111, 76, 111, +110, 103, 0, 105, 122, 101, 114, 111, 70, 108, 111, 97, 116, 0, 106, 122, 101, 114, 111, 68, 111, 117, 98, 108, +101, 0 + + +--- [output object] --- +{ + defaultString: "__defaultString__", + defaultBoolean: (boolean) false, + defaultList: [ + "__member__", + "__member__", + "__member__" + ], + defaultTimestamp: (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time, + defaultBlob: (Uint8Array) bytes[1, 0, 0, 1], + defaultByte: (number) 0, + defaultShort: (number) 0, + defaultInteger: (number) 0, + defaultLong: (number) 0, + defaultFloat: (number) 0, + defaultDouble: (number) 0, + defaultMap: { + key1: "__value__", + key2: "__value__" + }, + defaultEnum: "__defaultEnum__", + defaultIntEnum: (number) 0, + emptyString: "__emptyString__", + falseBoolean: (boolean) false, + emptyBlob: (Uint8Array) bytes[1, 0, 0, 1], + zeroByte: (number) 0, + zeroShort: (number) 0, + zeroInteger: (number) 0, + zeroLong: (number) 0, + zeroFloat: (number) 0, + zeroDouble: (number) 0, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OptionalInputOutput.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OptionalInputOutput.txt new file mode 100644 index 00000000000..9d9149c92dd --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/OptionalInputOutput.txt @@ -0,0 +1,53 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "value": "__value__" +} + +[actual bytes] +161, 101, 118, 97, 108, 117, 101, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95 + + +--- [output object] --- +{ + value: "__value__", + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RecursiveShapes.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RecursiveShapes.txt new file mode 100644 index 00000000000..812056399b1 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RecursiveShapes.txt @@ -0,0 +1,81 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "nested": { + "foo": "__foo__", + "nested": { + "bar": "__bar__", + "recursiveMember": { + "foo": "__foo__", + "nested": { + "bar": "__bar__", + "recursiveMember": {} + } + } + } + } +} + +[actual bytes] +161, 102, 110, 101, 115, 116, 101, 100, 162, 99, 102, 111, 111, 103, 95, 95, 102, 111, 111, 95, 95, 102, 110, 101, +115, 116, 101, 100, 162, 99, 98, 97, 114, 103, 95, 95, 98, 97, 114, 95, 95, 111, 114, 101, 99, 117, 114, 115, +105, 118, 101, 77, 101, 109, 98, 101, 114, 162, 99, 102, 111, 111, 103, 95, 95, 102, 111, 111, 95, 95, 102, 110, +101, 115, 116, 101, 100, 162, 99, 98, 97, 114, 103, 95, 95, 98, 97, 114, 95, 95, 111, 114, 101, 99, 117, 114, +115, 105, 118, 101, 77, 101, 109, 98, 101, 114, 160 + + +--- [output object] --- +{ + nested: { + foo: "__foo__", + nested: { + bar: "__bar__", + recursiveMember: { + foo: "__foo__", + nested: { + bar: "__bar__", + recursiveMember: {} + } + } + } + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborDenseMaps.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborDenseMaps.txt new file mode 100644 index 00000000000..de09cdd0a10 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborDenseMaps.txt @@ -0,0 +1,125 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "denseStructMap": { + "key1": { + "hi": "__hi__" + }, + "key2": { + "hi": "__hi__" + } + }, + "denseNumberMap": { + "key1": 0, + "key2": 0 + }, + "denseBooleanMap": { + "key1": false, + "key2": false + }, + "denseStringMap": { + "key1": "__value__", + "key2": "__value__" + }, + "denseSetMap": { + "key1": [ + "__member__", + "__member__", + "__member__" + ], + "key2": [ + "__member__", + "__member__", + "__member__" + ] + } +} + +[actual bytes] +165, 110, 100, 101, 110, 115, 101, 83, 116, 114, 117, 99, 116, 77, 97, 112, 162, 100, 107, 101, 121, 49, 161, 98, +104, 105, 102, 95, 95, 104, 105, 95, 95, 100, 107, 101, 121, 50, 161, 98, 104, 105, 102, 95, 95, 104, 105, 95, +95, 110, 100, 101, 110, 115, 101, 78, 117, 109, 98, 101, 114, 77, 97, 112, 162, 100, 107, 101, 121, 49, 0, 100, +107, 101, 121, 50, 0, 111, 100, 101, 110, 115, 101, 66, 111, 111, 108, 101, 97, 110, 77, 97, 112, 162, 100, 107, +101, 121, 49, 244, 100, 107, 101, 121, 50, 244, 110, 100, 101, 110, 115, 101, 83, 116, 114, 105, 110, 103, 77, 97, +112, 162, 100, 107, 101, 121, 49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, 121, 50, 105, 95, +95, 118, 97, 108, 117, 101, 95, 95, 107, 100, 101, 110, 115, 101, 83, 101, 116, 77, 97, 112, 162, 100, 107, 101, +121, 49, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, +95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 100, 107, 101, 121, 50, 131, 106, 95, 95, 109, 101, 109, +98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, +114, 95, 95 + + +--- [output object] --- +{ + denseStructMap: { + key1: { + hi: "__hi__" + }, + key2: { + hi: "__hi__" + } + }, + denseNumberMap: { + key1: (number) 0, + key2: (number) 0 + }, + denseBooleanMap: { + key1: (boolean) false, + key2: (boolean) false + }, + denseStringMap: { + key1: "__value__", + key2: "__value__" + }, + denseSetMap: { + key1: [ + "__member__", + "__member__", + "__member__" + ], + key2: [ + "__member__", + "__member__", + "__member__" + ] + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborLists.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborLists.txt new file mode 100644 index 00000000000..873701ba196 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborLists.txt @@ -0,0 +1,244 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "stringList": [ + "__member__", + "__member__", + "__member__" + ], + "stringSet": [ + "__member__", + "__member__", + "__member__" + ], + "integerList": [ + 0, + 0, + 0 + ], + "booleanList": [ + false, + false, + false + ], + "timestampList": [ + { + "tag": 1, + "value": 946702799.999 + }, + { + "tag": 1, + "value": 946702799.999 + }, + { + "tag": 1, + "value": 946702799.999 + } + ], + "enumList": [ + "__member__", + "__member__", + "__member__" + ], + "intEnumList": [ + 0, + 0, + 0 + ], + "nestedStringList": [ + [ + "__member__", + "__member__", + "__member__" + ], + [ + "__member__", + "__member__", + "__member__" + ], + [ + "__member__", + "__member__", + "__member__" + ] + ], + "structureList": [ + { + "a": "__a__", + "b": "__b__" + }, + { + "a": "__a__", + "b": "__b__" + }, + { + "a": "__a__", + "b": "__b__" + } + ], + "blobList": [ + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + }, + { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + } + ] +} + +[actual bytes] +170, 106, 115, 116, 114, 105, 110, 103, 76, 105, 115, 116, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, +106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 105, 115, +116, 114, 105, 110, 103, 83, 101, 116, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, +101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 107, 105, 110, 116, 101, 103, +101, 114, 76, 105, 115, 116, 131, 0, 0, 0, 107, 98, 111, 111, 108, 101, 97, 110, 76, 105, 115, 116, 131, 244, +244, 244, 109, 116, 105, 109, 101, 115, 116, 97, 109, 112, 76, 105, 115, 116, 131, 193, 251, 65, 204, 54, 196, 231, +255, 223, 59, 193, 251, 65, 204, 54, 196, 231, 255, 223, 59, 193, 251, 65, 204, 54, 196, 231, 255, 223, 59, 104, +101, 110, 117, 109, 76, 105, 115, 116, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, +101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 107, 105, 110, 116, 69, 110, +117, 109, 76, 105, 115, 116, 131, 0, 0, 0, 112, 110, 101, 115, 116, 101, 100, 83, 116, 114, 105, 110, 103, 76, +105, 115, 116, 131, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, +114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, +95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, +131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, +95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 109, 115, 116, 114, 117, 99, 116, 117, 114, 101, 76, 105, 115, 116, +131, 162, 97, 97, 101, 95, 95, 97, 95, 95, 97, 98, 101, 95, 95, 98, 95, 95, 162, 97, 97, 101, 95, 95, +97, 95, 95, 97, 98, 101, 95, 95, 98, 95, 95, 162, 97, 97, 101, 95, 95, 97, 95, 95, 97, 98, 101, 95, +95, 98, 95, 95, 104, 98, 108, 111, 98, 76, 105, 115, 116, 131, 68, 1, 0, 0, 1, 68, 1, 0, 0, 1, +68, 1, 0, 0, 1 + + +--- [output object] --- +{ + stringList: [ + "__member__", + "__member__", + "__member__" + ], + stringSet: [ + "__member__", + "__member__", + "__member__" + ], + integerList: [ + (number) 0, + (number) 0, + (number) 0 + ], + booleanList: [ + (boolean) false, + (boolean) false, + (boolean) false + ], + timestampList: [ + (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time, + (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time, + (Date) Fri, Dec 31, 1999, 20:59:59 Pacific Standard Time + ], + enumList: [ + "__member__", + "__member__", + "__member__" + ], + intEnumList: [ + (number) 0, + (number) 0, + (number) 0 + ], + nestedStringList: [ + [ + "__member__", + "__member__", + "__member__" + ], + [ + "__member__", + "__member__", + "__member__" + ], + [ + "__member__", + "__member__", + "__member__" + ] + ], + structureList: [ + { + a: "__a__", + b: "__b__" + }, + { + a: "__a__", + b: "__b__" + }, + { + a: "__a__", + b: "__b__" + } + ], + blobList: [ + (Uint8Array) bytes[1, 0, 0, 1], + (Uint8Array) bytes[1, 0, 0, 1], + (Uint8Array) bytes[1, 0, 0, 1] + ], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborSparseMaps.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborSparseMaps.txt new file mode 100644 index 00000000000..1eef1059ab5 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/RpcV2CborSparseMaps.txt @@ -0,0 +1,125 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "sparseStructMap": { + "key1": { + "hi": "__hi__" + }, + "key2": { + "hi": "__hi__" + } + }, + "sparseNumberMap": { + "key1": 0, + "key2": 0 + }, + "sparseBooleanMap": { + "key1": false, + "key2": false + }, + "sparseStringMap": { + "key1": "__value__", + "key2": "__value__" + }, + "sparseSetMap": { + "key1": [ + "__member__", + "__member__", + "__member__" + ], + "key2": [ + "__member__", + "__member__", + "__member__" + ] + } +} + +[actual bytes] +165, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 117, 99, 116, 77, 97, 112, 162, 100, 107, 101, 121, 49, 161, +98, 104, 105, 102, 95, 95, 104, 105, 95, 95, 100, 107, 101, 121, 50, 161, 98, 104, 105, 102, 95, 95, 104, 105, +95, 95, 111, 115, 112, 97, 114, 115, 101, 78, 117, 109, 98, 101, 114, 77, 97, 112, 162, 100, 107, 101, 121, 49, +0, 100, 107, 101, 121, 50, 0, 112, 115, 112, 97, 114, 115, 101, 66, 111, 111, 108, 101, 97, 110, 77, 97, 112, +162, 100, 107, 101, 121, 49, 244, 100, 107, 101, 121, 50, 244, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, +110, 103, 77, 97, 112, 162, 100, 107, 101, 121, 49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, +121, 50, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 108, 115, 112, 97, 114, 115, 101, 83, 101, 116, 77, 97, +112, 162, 100, 107, 101, 121, 49, 131, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, +109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 100, 107, 101, 121, 50, 131, 106, +95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, +109, 101, 109, 98, 101, 114, 95, 95 + + +--- [output object] --- +{ + sparseStructMap: { + key1: { + hi: "__hi__" + }, + key2: { + hi: "__hi__" + } + }, + sparseNumberMap: { + key1: (number) 0, + key2: (number) 0 + }, + sparseBooleanMap: { + key1: (boolean) false, + key2: (boolean) false + }, + sparseStringMap: { + key1: "__value__", + key2: "__value__" + }, + sparseSetMap: { + key1: [ + "__member__", + "__member__", + "__member__" + ], + key2: [ + "__member__", + "__member__", + "__member__" + ] + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SimpleScalarProperties.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SimpleScalarProperties.txt new file mode 100644 index 00000000000..9e0ecaed9af --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SimpleScalarProperties.txt @@ -0,0 +1,85 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "trueBooleanValue": false, + "falseBooleanValue": false, + "byteValue": 0, + "doubleValue": 0, + "floatValue": 0, + "integerValue": 0, + "longValue": 0, + "shortValue": 0, + "stringValue": "__stringValue__", + "blobValue": { + "type": "Buffer", + "data": [ + 1, + 0, + 0, + 1 + ] + } +} + +[actual bytes] +170, 112, 116, 114, 117, 101, 66, 111, 111, 108, 101, 97, 110, 86, 97, 108, 117, 101, 244, 113, 102, 97, 108, 115, +101, 66, 111, 111, 108, 101, 97, 110, 86, 97, 108, 117, 101, 244, 105, 98, 121, 116, 101, 86, 97, 108, 117, 101, +0, 107, 100, 111, 117, 98, 108, 101, 86, 97, 108, 117, 101, 0, 106, 102, 108, 111, 97, 116, 86, 97, 108, 117, +101, 0, 108, 105, 110, 116, 101, 103, 101, 114, 86, 97, 108, 117, 101, 0, 105, 108, 111, 110, 103, 86, 97, 108, +117, 101, 0, 106, 115, 104, 111, 114, 116, 86, 97, 108, 117, 101, 0, 107, 115, 116, 114, 105, 110, 103, 86, 97, +108, 117, 101, 111, 95, 95, 115, 116, 114, 105, 110, 103, 86, 97, 108, 117, 101, 95, 95, 105, 98, 108, 111, 98, +86, 97, 108, 117, 101, 68, 1, 0, 0, 1 + + +--- [output object] --- +{ + trueBooleanValue: (boolean) false, + falseBooleanValue: (boolean) false, + byteValue: (number) 0, + doubleValue: (number) 0, + floatValue: (number) 0, + integerValue: (number) 0, + longValue: (number) 0, + shortValue: (number) 0, + stringValue: "__stringValue__", + blobValue: (Uint8Array) bytes[1, 0, 0, 1], + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + diff --git a/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SparseNullsOperation.txt b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SparseNullsOperation.txt new file mode 100644 index 00000000000..7b7414f0268 --- /dev/null +++ b/private/smithy-rpcv2-cbor-schema/test/snapshots/res/SparseNullsOperation.txt @@ -0,0 +1,73 @@ +======================== minimal response ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{} + +[actual bytes] +160 + + +--- [output object] --- +{ + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} + +======================== w/ optional fields ======================== +[status] 200 + +smithy-protocol: rpc-v2-cbor +content-type: application/cbor + +[Uint8Array (cbor object view)] +{ + "sparseStringList": [ + "__member__", + "__member__", + "__member__" + ], + "sparseStringMap": { + "key1": "__value__", + "key2": "__value__" + } +} + +[actual bytes] +162, 112, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, 110, 103, 76, 105, 115, 116, 131, 106, 95, 95, 109, 101, +109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, 101, 114, 95, 95, 106, 95, 95, 109, 101, 109, 98, +101, 114, 95, 95, 111, 115, 112, 97, 114, 115, 101, 83, 116, 114, 105, 110, 103, 77, 97, 112, 162, 100, 107, 101, +121, 49, 105, 95, 95, 118, 97, 108, 117, 101, 95, 95, 100, 107, 101, 121, 50, 105, 95, 95, 118, 97, 108, 117, +101, 95, 95 + + +--- [output object] --- +{ + sparseStringList: [ + "__member__", + "__member__", + "__member__" + ], + sparseStringMap: { + key1: "__value__", + key2: "__value__" + }, + $metadata: { + httpStatusCode: (number) 200, + requestId: (undefined), + extendedRequestId: (undefined), + cfId: (undefined), + attempts: (number) 1, + totalRetryDelay: (number) 0 + } +} +