Skip to content

Commit

Permalink
test(middleware): integ tests for sdk clients (#4686)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed May 3, 2023
1 parent 02b68de commit 793a192
Show file tree
Hide file tree
Showing 23 changed files with 705 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TranscribeStreaming } from "@aws-sdk/client-transcribe-streaming";
import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-eventstream", () => {
// TODO: http2 in CI
xdescribe(LexRuntimeV2.name, () => {
it("should set streaming headers", async () => {
const client = new LexRuntimeV2({ region: "us-west-2" });
Expand Down Expand Up @@ -67,6 +68,7 @@ describe("middleware-eventstream", () => {
});
});

// TODO: http2 in CI
xdescribe(TranscribeStreaming.name, () => {
it("should set streaming headers", async () => {
const client = new TranscribeStreaming({ region: "us-west-2" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe("middleware-flexible-checksums", () => {
"amz-sdk-invocation-id": /./,
"amz-sdk-request": /./,
"x-amz-date": /./,
"x-amz-security-token": /./,
"x-amz-content-sha256": "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589",
authorization: /./,
},
Expand Down Expand Up @@ -63,7 +62,6 @@ describe("middleware-flexible-checksums", () => {
"amz-sdk-invocation-id": /./,
"amz-sdk-request": /./,
"x-amz-date": /./,
"x-amz-security-token": /./,
authorization: /./,
// this is here even if algo is SHA1
"x-amz-content-sha256": "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589",
Expand Down
3 changes: 2 additions & 1 deletion packages/middleware-sdk-api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { APIGateway } from "@aws-sdk/client-api-gateway";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-sdk-api-gateway", () => {
describe(APIGateway.name, () => {
it("should add accept header", async () => {
const client = new APIGateway({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
headers: {
accept: "application/json",
},
});

await client.getApiKeys({});

expect.hasAssertions();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("EC2", () => {
expect(parse.get("Version")).toEqual("2016-11-15");
const psu = parse.get("PresignedUrl") as string;
const matcher =
/https\:\/\/ec2\.us-west-2\.amazonaws\.com\/\?Action=CopySnapshot&DestinationRegion=us-east-1&SourceRegion=us-west-2&SourceSnapshotId=my-snapshot-id&Version=2016-11-15&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=(.+)\%2Fus-west-2\%2Fec2\%2Faws4_request&X-Amz-Date=(\d{8})T(\d{6})Z&X-Amz-Expires=3600&X-Amz-Security-Token=(.+)&X-Amz-Signature=(.+)&X-Amz-SignedHeaders=host/;
/https\:\/\/ec2\.us-west-2\.amazonaws\.com\/\?Action=CopySnapshot&DestinationRegion=us-east-1&SourceRegion=us-west-2&SourceSnapshotId=my-snapshot-id&Version=2016-11-15&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=(.+)\%2Fus-west-2\%2Fec2\%2Faws4_request&X-Amz-Date=(\d{8})T(\d{6})Z&X-Amz-Expires=3600(&X-Amz-Security-Token=(.+))?&X-Amz-Signature=(.+)&X-Amz-SignedHeaders=host/;

expect(psu).toMatch(matcher);
},
Expand Down Expand Up @@ -60,7 +60,7 @@ describe("EC2", () => {
expect(parse.get("Version")).toEqual("2016-11-15");
const psu = parse.get("PresignedUrl") as string;
const matcher =
/https\:\/\/ec2\.us-west-2\.amazonaws\.com\/\?Action=CopySnapshot&DestinationRegion=us-east-1&Encrypted=true&KmsKeyId=my-kms-key&SourceRegion=us-west-2&SourceSnapshotId=my-snapshot-id&Version=2016-11-15&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=(.+)\%2Fus-west-2\%2Fec2\%2Faws4_request&X-Amz-Date=(\d{8})T(\d{6})Z&X-Amz-Expires=3600&X-Amz-Security-Token=(.+)&X-Amz-Signature=(.+)&X-Amz-SignedHeaders=host/;
/https\:\/\/ec2\.us-west-2\.amazonaws\.com\/\?Action=CopySnapshot&DestinationRegion=us-east-1&Encrypted=true&KmsKeyId=my-kms-key&SourceRegion=us-west-2&SourceSnapshotId=my-snapshot-id&Version=2016-11-15&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=(.+)\%2Fus-west-2\%2Fec2\%2Faws4_request&X-Amz-Date=(\d{8})T(\d{6})Z&X-Amz-Expires=3600(&X-Amz-Security-Token=(.+))?&X-Amz-Signature=(.+)&X-Amz-SignedHeaders=host/;

expect(psu).toMatch(matcher);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/middleware-sdk-glacier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Glacier } from "@aws-sdk/client-glacier";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-sdk-glacier", () => {
describe(Glacier.name, () => {
it("should set a default account id", async () => {
const client = new Glacier({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
path: `/-/vaults`,
});

await client.listVaults({
accountId: undefined,
});

expect.hasAssertions();
});

it("should not override account id", async () => {
const client = new Glacier({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
path: `/1234/vaults`,
});

await client.listVaults({
accountId: "1234",
});

expect.hasAssertions();
});

describe("headers", () => {
it("should set checksum and api version headers", async () => {
const client = new Glacier({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
headers: {
"x-amz-glacier-version": "2012-06-01",
"x-amz-content-sha256": "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589",
"x-amz-sha256-tree-hash": "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589",
},
});

await client.uploadArchive({
vaultName: "vault",
accountId: "1234",
body: Buffer.from("abcd"),
});

expect.hasAssertions();
});
});
});
});
3 changes: 2 additions & 1 deletion packages/middleware-sdk-machinelearning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MachineLearning } from "@aws-sdk/client-machine-learning";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-sdk-machine-learning", () => {
describe(MachineLearning.name, () => {
it("should use the input predict endpoint", async () => {
const client = new MachineLearning({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
hostname: "predict-custom-endpoint.us-west-2.amazonaws.com",
protocol: "https:",
path: "/my-path",
query: {
apples: "oranges",
},
});

await client.predict({
PredictEndpoint: `https://predict-custom-endpoint.us-west-2.amazonaws.com/my-path?apples=oranges`,
MLModelId: "1",
Record: {
hello: "world",
},
});

expect.hasAssertions();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe(RDS.name, () => {
expect(presignedUrl).toMatch(/Action=CopyDBClusterSnapshot/);
expect(presignedUrl).not.toMatch(/KmsKeyId=/);
expect(presignedUrl).toMatch(/Version=2014-10-31/);
expect(presignedUrl).toMatch(/X-Amz-Security-Token=(.*?)/);
expect(presignedUrl).toMatch(/X-Amz-Algorithm=AWS4-HMAC-SHA256/);
expect(presignedUrl).toMatch(/X-Amz-SignedHeaders=host/);
expect(presignedUrl).toMatch(/X-Amz-Credential=/);
Expand Down Expand Up @@ -71,7 +70,6 @@ describe(RDS.name, () => {
expect(presignedUrl).toMatch(/Action=CopyDBSnapshot/);
expect(presignedUrl).toMatch(/KmsKeyId=my-kms-key/);
expect(presignedUrl).toMatch(/Version=2014-10-31/);
expect(presignedUrl).toMatch(/X-Amz-Security-Token=(.*?)/);
expect(presignedUrl).toMatch(/X-Amz-Algorithm=AWS4-HMAC-SHA256/);
expect(presignedUrl).toMatch(/X-Amz-SignedHeaders=host/);
expect(presignedUrl).toMatch(/X-Amz-Credential=/);
Expand Down Expand Up @@ -113,7 +111,6 @@ describe(RDS.name, () => {
expect(presignedUrl).toMatch(/Action=StartDBInstanceAutomatedBackupsReplication/);
expect(presignedUrl).toMatch(/KmsKeyId=my-kms-key/);
expect(presignedUrl).toMatch(/Version=2014-10-31/);
expect(presignedUrl).toMatch(/X-Amz-Security-Token=(.*?)/);
expect(presignedUrl).toMatch(/X-Amz-Algorithm=AWS4-HMAC-SHA256/);
expect(presignedUrl).toMatch(/X-Amz-SignedHeaders=host/);
expect(presignedUrl).toMatch(/X-Amz-Credential=/);
Expand Down
3 changes: 2 additions & 1 deletion packages/middleware-sdk-route53/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Route53 } from "@aws-sdk/client-route-53";
import { XMLParser } from "fast-xml-parser";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-sdk-route53", () => {
describe(Route53.name, () => {
it("should normalize param names HostedZoneId", async () => {
const client = new Route53({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
body: /<HostedZoneId>my-zone<\/HostedZoneId>/,
});

await client.createKeySigningKey({
HostedZoneId: "/hostedzone/my-zone",
CallerReference: "abcd",
KeyManagementServiceArn: "arn",
Name: "name",
Status: "ACTIVE",
});

expect.hasAssertions();
});

it("should normalize param names DelegationSetId", async () => {
const client = new Route53({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
body: /<DelegationSetId>my-set<\/DelegationSetId>/,
});

await client.createHostedZone({
CallerReference: "abcd",
Name: "name",
DelegationSetId: "/delegationset/my-set",
});

expect.hasAssertions();
});

it("should normalize param names Id", async () => {
const client = new Route53({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
path: "/2013-04-01/change/my-change",
});

await client.getChange({
Id: "/change/my-change",
});

expect.hasAssertions();
});

it("should update change resource record sets request", async () => {
const client = new Route53({
region: "us-west-2",
});

requireRequestsFrom(client).toMatch({
body(raw) {
const parsed = new XMLParser().parse(raw);
expect(
parsed.ChangeResourceRecordSetsRequest.ChangeBatch.Changes.Change.ResourceRecordSet.AliasTarget.HostedZoneId
).toMatch(/^my-zone$/);
},
});

await client.changeResourceRecordSets({
HostedZoneId: "zone",
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
ResourceRecordSet: {
Name: "name",
Type: "CNAME",
AliasTarget: {
HostedZoneId: "/hostedzone/my-zone",
DNSName: "dns-name",
EvaluateTargetHealth: false,
},
},
},
],
},
});

expect.hasAssertions();
});
});
});
3 changes: 2 additions & 1 deletion packages/middleware-sdk-s3-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Loading

0 comments on commit 793a192

Please sign in to comment.