Skip to content

Commit

Permalink
test(clients): add mock credentials to client instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 29, 2024
1 parent ecb833e commit d520cbd
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 20 deletions.
8 changes: 7 additions & 1 deletion clients/client-eventbridge/test/EventBridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { describe, expect, test as it } from "vitest";
import { EventBridge } from "../src/EventBridge";

describe("EventBridge", () => {
const client = new EventBridge({});
const client = new EventBridge({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
// and return them in the Metadata.
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
Expand Down
10 changes: 8 additions & 2 deletions clients/client-kinesis/test/Kinesis.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { test as it, describe, expect } from "vitest";
import { describe, expect, test as it } from "vitest";

import { KinesisClient, ListStreamsCommand } from "../src/index";

describe("@aws-sdk/client-kinesis", () => {
const client = new KinesisClient({});
const client = new KinesisClient({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
const ONE_SECOND = 1 * 1000;

// TODO: not working in CI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe("@aws-sdk/client-lex-runtime-service", () => {
};
const client = new LexRuntimeService({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
Expand Down
4 changes: 4 additions & 0 deletions clients/client-mediastore-data/test/MediaStoreData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe("@aws-sdk/client-mediastore-data", () => {
};
const client = new MediaStoreData({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("@aws-sdk/client-s3", () => {
credentials: fromNodeProviderChain(),
requestHandler: new FetchHttpHandler(),
})
) as S3;
) as unknown as S3;
});

describe("PutObject", () => {
Expand Down
47 changes: 42 additions & 5 deletions clients/client-s3/test/unit/S3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ describe("endpoint", () => {
expect(request.path).to.equal("/path/bucket/key");
return Promise.resolve({ output: {} as any, response: {} as any });
};
const client = new S3({ endpoint: "http://localhost:8080/path", forcePathStyle: true });
const client = new S3({
endpoint: "http://localhost:8080/path",
forcePathStyle: true,
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});

client.middlewareStack.add(endpointValidator, {
step: "serialize",
Expand Down Expand Up @@ -48,7 +56,13 @@ describe("Endpoints from ARN", () => {

describe("Accesspoint ARN", async () => {
it("should succeed with access point ARN", async () => {
const client = new S3({ region: "us-west-2" });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "build", priority: "low" });
const result: any = await client.putObject({
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",
Expand Down Expand Up @@ -151,6 +165,10 @@ describe("Throw 200 response", () => {

const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
requestHandler: {
handle: async () => ({
response,
Expand Down Expand Up @@ -228,7 +246,13 @@ describe("regional endpoints", () => {
};

it("should use regional endpoints if region is us-east-1", async () => {
const client = new S3({ region: "us-east-1" });
const client = new S3({
region: "us-east-1",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Expand All @@ -239,7 +263,13 @@ describe("regional endpoints", () => {
});

it("should use global endpoints if region is aws-global", async () => {
const client = new S3({ region: "aws-global" });
const client = new S3({
region: "aws-global",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Expand All @@ -263,7 +293,14 @@ describe("signing", () => {
},
};

const client = new S3({ requestHandler });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
requestHandler,
});
return await client.putObject({
Bucket: "bucket",
Key: "some file.txt",
Expand Down
5 changes: 3 additions & 2 deletions clients/client-s3/test/unit/dotSegmentInUriLabel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test as it, describe, expect } from "vitest";

import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
import { HttpHandlerOptions } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { S3 } from "../../src/S3";

/**
Expand All @@ -25,6 +25,7 @@ class RequestSerializationTestHandler implements HttpHandler {

describe("Dot Segment in URI Label", () => {
const client = new S3({
region: "us-west-2",
credentials: { accessKeyId: "mockAccessKeyId", secretAccessKey: "mockSecretAccessKey" },
requestHandler: new RequestSerializationTestHandler(),
});
Expand Down
29 changes: 23 additions & 6 deletions clients/client-s3/test/unit/flexibleChecksums.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { test as it, describe, expect } from "vitest";

import { ChecksumAlgorithm } from "@aws-sdk/middleware-flexible-checksums";
import { HttpRequest } from "@smithy/protocol-http";
import { BuildMiddleware } from "@smithy/types";
import { Readable } from "stream";
import { describe, expect, test as it } from "vitest";

import { S3, ChecksumAlgorithm as Algo } from "../../src/index";
import { ChecksumAlgorithm as Algo, S3 } from "../../src/index";

describe("Flexible Checksums", () => {
const testCases = [
Expand Down Expand Up @@ -55,7 +54,13 @@ describe("Flexible Checksums", () => {
return { output: {} as any, response: {} as any };
};

const client = new S3({});
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.addRelativeTo(requestChecksumValidator, {
relation: "after",
toMiddleware: "flexibleChecksumsMiddleware",
Expand Down Expand Up @@ -89,7 +94,13 @@ describe("Flexible Checksums", () => {
return { output: {} as any, response: {} as any };
};

const client = new S3({});
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.addRelativeTo(requestChecksumValidator, {
relation: "after",
toMiddleware: "flexibleChecksumsMiddleware",
Expand Down Expand Up @@ -133,7 +144,13 @@ describe("Flexible Checksums", () => {
};
};

const client = new S3({});
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.addRelativeTo(responseChecksumValidator, {
relation: "after",
toMiddleware: "flexibleChecksumsMiddleware",
Expand Down
11 changes: 8 additions & 3 deletions clients/client-transcribe-streaming/test/index.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { test as it, afterAll, describe, expect } from "vitest";

import { createReadStream } from "fs";
import { join } from "path";
import { afterAll, describe, expect, test as it } from "vitest";

import { TranscribeStreaming } from "../src/index";
const audio = createReadStream(join(__dirname, "numbers.wav"));

describe("TranscribeStream client", () => {
const client = new TranscribeStreaming({});
const client = new TranscribeStreaming({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
afterAll(() => {
client.destroy();
});
Expand Down

0 comments on commit d520cbd

Please sign in to comment.