forked from smithy-lang/smithy-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
676 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@smithy/middleware-apply-body-checksum": patch | ||
"@smithy/middleware-content-length": patch | ||
"@smithy/middleware-retry": patch | ||
"@smithy/middleware-serde": patch | ||
"@smithy/util-stream": patch | ||
--- | ||
|
||
Add integration tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"clean": "turbo run clean --force --parallel", | ||
"build": "turbo run build", | ||
"test": "turbo run test", | ||
"test:integration": "turbo run test:integration", | ||
"lint": "turbo run lint", | ||
"format": "turbo run format --parallel", | ||
"stage-release": "turbo run stage-release", | ||
|
@@ -65,7 +66,8 @@ | |
"packages/*", | ||
"smithy-typescript-ssdk-libs/*", | ||
"smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/source/typescript-codegen", | ||
"smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/ssdk-test/typescript-ssdk-codegen" | ||
"smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/ssdk-test/typescript-ssdk-codegen", | ||
"private/*" | ||
], | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/middleware-apply-body-checksum/src/middleware-apply-body-checksum.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
import { Weather } from "weather"; | ||
|
||
describe("middleware-apply-body-checksum", () => { | ||
describe(Weather.name, () => { | ||
it("should add body-checksum", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
requireRequestsFrom(client).toMatch({ | ||
headers: { | ||
"content-md5": /^.{22}(==)?$/i, | ||
}, | ||
}); | ||
|
||
await client.getCity({ | ||
cityId: "my-city", | ||
}); | ||
|
||
expect.assertions(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/middleware-content-length/src/middleware-content-length.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
import { Weather } from "weather"; | ||
|
||
describe("middleware-content-length", () => { | ||
describe(Weather.name, () => { | ||
it("should not add content-length if no body", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
requireRequestsFrom(client).toMatch({ | ||
headers: { | ||
"content-length": /undefined/, | ||
}, | ||
}); | ||
|
||
await client.getCity({ | ||
cityId: "my-city", | ||
}); | ||
|
||
expect.assertions(1); | ||
}); | ||
|
||
// Weather uses TestProtocolGenerator, which serializes all bodies as `{}`. | ||
// This tests that content-length gets set to `2`, only where bodies are | ||
// sent in the request. | ||
it("should add content-length if body present", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
requireRequestsFrom(client).toMatch({ | ||
headers: { | ||
"content-length": /2/, | ||
}, | ||
}); | ||
|
||
console.log(client.middlewareStack); | ||
|
||
await client.createCity({ | ||
name: "MyCity", | ||
coordinates: { | ||
latitude: 0, | ||
longitude: 0, | ||
}, | ||
}); | ||
|
||
expect.assertions(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/middleware-retry/src/middleware-retry.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
import { Weather } from "weather"; | ||
|
||
describe("middleware-retry", () => { | ||
describe(Weather.name, () => { | ||
it("should set retry headers", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
|
||
requireRequestsFrom(client).toMatch({ | ||
hostname: "foo.bar", | ||
headers: { | ||
"amz-sdk-invocation-id": /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/, | ||
"amz-sdk-request": "attempt=1; max=3", | ||
}, | ||
}); | ||
|
||
await client.getCity({ | ||
cityId: "my-city", | ||
}); | ||
|
||
expect.hasAssertions(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/middleware-serde/src/middleware-serde.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
import { Weather } from "weather"; | ||
|
||
describe("middleware-serde", () => { | ||
describe(Weather.name, () => { | ||
it("should serialize TestProtocol", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
requireRequestsFrom(client).toMatch({ | ||
method: "PUT", | ||
hostname: "foo.bar", | ||
body: "{}", | ||
protocol: "https:", | ||
path: "/city", | ||
}); | ||
await client.createCity({ | ||
name: "MyCity", | ||
coordinates: { | ||
latitude: 0, | ||
longitude: 0, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { HttpResponse } from "@smithy/protocol-http"; | ||
import { HttpRequest as IHttpRequest } from "@smithy/types"; | ||
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream"; | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
import { fromUtf8 } from "@smithy/util-utf8"; | ||
import { Readable } from "stream"; | ||
import { Weather } from "weather"; | ||
|
||
describe("util-stream", () => { | ||
describe(Weather.name, () => { | ||
it("should be uniform between string and Uint8Array payloads", async () => { | ||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
requireRequestsFrom(client).toMatch({ | ||
method: "POST", | ||
hostname: "foo.bar", | ||
query: {}, | ||
headers: { | ||
"content-type": "application/octet-stream", | ||
"content-length": "17", | ||
}, | ||
body(raw) { | ||
expect(raw.toString("utf-8")).toEqual('{"hello":"world"}'); | ||
}, | ||
protocol: "https:", | ||
path: "/invoke", | ||
}); | ||
|
||
// string | ||
await client.invoke({ | ||
payload: JSON.stringify({ | ||
hello: "world", | ||
}), | ||
}); | ||
|
||
// Uint8Array | ||
await client.invoke({ | ||
payload: Buffer.from( | ||
JSON.stringify({ | ||
hello: "world", | ||
}) | ||
), | ||
}); | ||
}); | ||
}); | ||
|
||
describe("blob helper integration", () => { | ||
const FunctionName = "echo"; | ||
|
||
const client = new Weather({ endpoint: "https://foo.bar" }); | ||
|
||
requireRequestsFrom(client).toMatch({ | ||
method: "POST", | ||
hostname: "foo.bar", | ||
query: {}, | ||
headers: { | ||
"content-type": "application/octet-stream", | ||
}, | ||
protocol: "https:", | ||
path: "/invoke", | ||
}); | ||
|
||
client.config.requestHandler = new (class { | ||
async handle(request: IHttpRequest) { | ||
return { | ||
response: new HttpResponse({ | ||
statusCode: 200, | ||
body: typeof request.body === "string" ? fromUtf8(request.body) : Uint8Array.from(request.body), | ||
}), | ||
}; | ||
} | ||
})(); | ||
|
||
it("should allow string as payload blob and allow conversion of output payload blob to string", async () => { | ||
const payload = JSON.stringify({ hello: "world" }); | ||
const invoke = await client.invoke({ payload: payload }); | ||
expect(JSON.parse(invoke?.payload?.transformToString() ?? "{}")).toEqual({ hello: "world" }); | ||
}); | ||
|
||
it("should allow Uint8Array as payload blob", async () => { | ||
const payload = Uint8ArrayBlobAdapter.fromString(JSON.stringify({ hello: "world" })); | ||
const invoke = await client.invoke({ payload: payload }); | ||
expect(JSON.parse(invoke?.payload?.transformToString() ?? "{}")).toEqual({ hello: "world" }); | ||
}); | ||
|
||
it("should allow buffer as payload blob", async () => { | ||
// note: Buffer extends Uint8Array | ||
const payload = Buffer.from(Uint8ArrayBlobAdapter.fromString(JSON.stringify({ hello: "world" }))); | ||
const invoke = await client.invoke({ payload: payload }); | ||
expect(JSON.parse(invoke?.payload?.transformToString() ?? "{}")).toEqual({ hello: "world" }); | ||
}); | ||
|
||
it("should allow stream as payload blob but not be able to sign it", async () => { | ||
const payload = Readable.from(Buffer.from(Uint8ArrayBlobAdapter.fromString(JSON.stringify({ hello: "world" }))), { | ||
encoding: "utf-8", | ||
}); | ||
expect(JSON.parse(await streamToString(payload))).toEqual({ hello: "world" }); | ||
await client.invoke({ payload: payload }).catch((e) => { | ||
expect(e.toString()).toContain("InvalidSignatureException"); | ||
}); | ||
expect.hasAssertions(); | ||
}); | ||
}); | ||
|
||
function streamToString(stream: Readable): Promise<string> { | ||
const chunks: any[] = []; | ||
return new Promise((resolve, reject) => { | ||
stream.on("data", (chunk) => chunks.push(Buffer.from(chunk))); | ||
stream.on("error", (err) => reject(err)); | ||
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8"))); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/node_modules/ | ||
/build/ | ||
/coverage/ | ||
/docs/ | ||
*.tsbuildinfo | ||
*.tgz | ||
*.log | ||
package-lock.json |
Oops, something went wrong.