Skip to content

Commit

Permalink
test: create e2e global hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 31, 2024
1 parent 05d9ef8 commit 8411603
Show file tree
Hide file tree
Showing 29 changed files with 63 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { beforeAll, describe, expect, test as it } from "vitest";

import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
Expand All @@ -9,6 +10,7 @@ describe("@aws-sdk/client-cognito-identity", () => {
let IdentityPoolId: string;

beforeAll(async () => {
await setTestCredentials();
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

Expand Down
1 change: 1 addition & 0 deletions clients/client-cognito-identity/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "happy-dom",
env: process.env as Record<string, string>,
},
});
11 changes: 6 additions & 5 deletions clients/client-kinesis/test/Kinesis.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { describe, expect, test as it } from "vitest";
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { beforeAll, describe, expect, test as it } from "vitest";

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

describe("@aws-sdk/client-kinesis", () => {
beforeAll(async () => {
await setTestCredentials();
});

const client = new KinesisClient({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
const ONE_SECOND = 1 * 1000;

Expand Down
1 change: 1 addition & 0 deletions clients/client-kinesis/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
6 changes: 2 additions & 4 deletions clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* This is the integration test that make sure the client can make request cross-platform-ly
* in NodeJS and browsers.
*/
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import type { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
Expand All @@ -20,6 +17,7 @@ describe("@aws-sdk/client-s3", () => {
let Key = `${Date.now()}`;

beforeAll(async () => {
await setTestCredentials();
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

Expand Down
6 changes: 2 additions & 4 deletions clients/client-s3/test/e2e/S3.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@aws-sdk/signature-v4-crt";

import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
import { AwsCredentialIdentity } from "@aws-sdk/types";
import { afterAll, afterEach, beforeAll, describe, expect, test as it } from "vitest";

import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
Expand All @@ -13,23 +13,21 @@ describe("@aws-sdk/client-s3", () => {
let client: S3;
let Bucket: string;
let region: string;
let credentials: AwsCredentialIdentity;
let mrapArn: string;

beforeAll(async () => {
await setTestCredentials();
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

region = process?.env?.AWS_SMOKE_TEST_REGION as string;
credentials = (globalThis as any).credentials || undefined;
Bucket = process?.env?.AWS_SMOKE_TEST_BUCKET as string;
mrapArn = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_MRAP_ARN || process?.env?.AWS_SMOKE_TEST_MRAP_ARN;

Key = ``;

client = new S3({
region,
credentials,
});
});

Expand Down
1 change: 1 addition & 0 deletions clients/client-s3/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
exclude: ["**/*.browser.e2e.spec.ts"],
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
7 changes: 6 additions & 1 deletion clients/client-transcribe-streaming/test/index.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { createReadStream } from "fs";
import { join } from "path";
import { afterAll, describe, expect, test as it } from "vitest";
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";

import { TranscribeStreaming } from "../src/index";
const audio = createReadStream(join(__dirname, "numbers.wav"));
Expand All @@ -13,6 +14,10 @@ describe("TranscribeStream client", () => {
secretAccessKey: "CLIENT_TEST",
},
});

beforeAll(async () => {
await setTestCredentials();
});
afterAll(() => {
client.destroy();
});
Expand Down
1 change: 1 addition & 0 deletions clients/client-transcribe-streaming/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
2 changes: 2 additions & 0 deletions lib/lib-dynamodb/src/test/lib-dynamodb.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import {
BillingMode,
CreateTableCommandOutput,
Expand Down Expand Up @@ -196,6 +197,7 @@ describe(
const passError = (e: any) => e;

beforeAll(async () => {
await setTestCredentials();
log.describe = await dynamodb
.describeTable({
TableName,
Expand Down
1 change: 1 addition & 0 deletions lib/lib-dynamodb/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
5 changes: 2 additions & 3 deletions lib/lib-storage/src/lib-storage.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { S3 } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
import type { AwsCredentialIdentity } from "@smithy/types";
Expand All @@ -14,14 +15,13 @@ describe("@aws-sdk/lib-storage", () => {
let dataString: string;
let Bucket: string;
let region: string;
let credentials: AwsCredentialIdentity;

beforeAll(async () => {
await setTestCredentials();
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

region = process?.env?.AWS_SMOKE_TEST_REGION as string;
credentials = (globalThis as any).credentials || undefined;
Bucket = process?.env?.AWS_SMOKE_TEST_BUCKET as string;

Key = ``;
Expand All @@ -30,7 +30,6 @@ describe("@aws-sdk/lib-storage", () => {

client = new S3({
region,
credentials,
});
});

Expand Down
1 change: 1 addition & 0 deletions lib/lib-storage/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"local-publish": "node ./scripts/verdaccio-publish/index.js",
"test:all": "yarn build:all && jest --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
"test:ci": "lerna run test --since origin/main",
"test:e2e": "node ./scripts/turbo test:e2e && node ./tests/canary/canary",
"test:e2e": "node -e \"console.log(process.env)\" && node ./scripts/turbo test:e2e && node ./tests/canary/canary",
"test:e2e:legacy": "cucumber-js --fail-fast",
"test:e2e:legacy:preview": "./tests/e2e-legacy/preview.mjs",
"test:e2e:legacy:since:release": "./tests/e2e-legacy/since-release.mjs",
Expand Down
2 changes: 2 additions & 0 deletions packages/ec2-metadata-service/src/MetadataService.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { fromInstanceMetadata } from "@aws-sdk/credential-providers";
import { beforeAll, describe, expect, test as it, vi } from "vitest";

Expand All @@ -9,6 +10,7 @@ describe("MetadataService E2E Tests", () => {
let metadataServiceAvailable: any;

beforeAll(async () => {
await setTestCredentials();
try {
await provider();
metadataServiceAvailable = true;
Expand Down
1 change: 1 addition & 0 deletions packages/ec2-metadata-service/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { S3 } from "@aws-sdk/client-s3";
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
Expand All @@ -22,6 +23,7 @@ describe("S3 Global Client Test", () => {
const randId = alphabet[(Math.random() * alphabet.length) | 0] + alphabet[(Math.random() * alphabet.length) | 0];

beforeAll(async () => {
await setTestCredentials();
callerID = await stsClient.getCallerIdentity({});
bucketNames = regionConfigs.map((config) => `${callerID.Account}-${randId}-redirect-${config.region}`);
await Promise.all(bucketNames.map((bucketName, index) => deleteBucket(s3Clients[index], bucketName)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { S3 } from "@aws-sdk/client-s3";
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
import { afterAll, beforeAll, describe, expect, test as it, vi } from "vitest";
Expand All @@ -24,6 +25,7 @@ describe("S3 Expires e2e test", () => {
const randId = alphabet[(Math.random() * alphabet.length) | 0] + alphabet[(Math.random() * alphabet.length) | 0];

beforeAll(async () => {
await setTestCredentials();
callerID = await stsClient.getCallerIdentity({});
Bucket = `${callerID.Account}-${randId}-s3-expires`;
await s3.createBucket({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { GetObjectCommand, PutObjectCommand, S3, waitUntilBucketExists } from "@aws-sdk/client-s3";
import { STS } from "@aws-sdk/client-sts";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
Expand Down Expand Up @@ -34,6 +35,7 @@ describe("s3 express CRUD test suite", () => {
let readWriteDeleteRecorder: typeof recorder.calls;

beforeAll(async () => {
await setTestCredentials();
({ s3, controller, bucketName, recorder } = await createClientAndRecorder());

await s3.createBucket({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { S3 } from "@aws-sdk/client-s3";
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
import { afterAll, beforeAll, describe, test as it } from "vitest";
Expand All @@ -15,6 +16,7 @@ describe("S3 throw 200 exceptions", () => {
let callerID: GetCallerIdentityCommandOutput;

beforeAll(async () => {
await setTestCredentials();
callerID = await stsClient.getCallerIdentity({});
Bucket = `${callerID.Account}-${randId}-s3-200s-e2e-test-empty-${config.region}-${(Date.now() / 1000) | 0}`;

Expand Down
1 change: 1 addition & 0 deletions packages/middleware-sdk-s3/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Run using AWS_SMOKE_TEST_REGION=[Region] AWS_SMOKE_TEST_BUCKET=[Bucket] yarn test:e2e
// These params are established in /tests/e2e.
import { setTestCredentials } from "@aws-sdk/aws-util-test";
import { NoSuchKey, S3 } from "@aws-sdk/client-s3";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test as it } from "vitest";

Expand All @@ -16,6 +15,7 @@ describe(createPresignedPost.name, () => {
let region: string;

beforeAll(async () => {
await setTestCredentials();
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

Expand Down
1 change: 1 addition & 0 deletions packages/s3-presigned-post/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default defineConfig({
test: {
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});
1 change: 1 addition & 0 deletions private/aws-util-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@aws-sdk/aws-protocoltests-json": "*",
"@smithy/protocol-http": "^4.1.4",
"@smithy/shared-ini-file-loader": "^3.1.8",
"@smithy/types": "^3.5.0",
"tslib": "^2.6.2"
},
Expand Down
1 change: 1 addition & 0 deletions private/aws-util-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./requests/test-http-handler";
export * from "./set-test-credentials";
3 changes: 3 additions & 0 deletions private/aws-util-test/src/set-test-credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const setTestCredentials = async () => {
// no-op
};
9 changes: 9 additions & 0 deletions scripts/turbo/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// Build script to handle Turborepo build execution
const { spawnProcess } = require("../utils/spawn-process");
const path = require("path");
const { loadSharedConfigFiles } = require("@smithy/shared-ini-file-loader");

const runTurbo = async (task, args, { apiSecret, apiEndpoint, apiSignatureKey } = {}) => {
const command = ["turbo", "run", task, "--concurrency=100%", "--output-logs=hash-only"];
command.push(...args);
const turboRoot = path.join(__dirname, "..", "..");

const ini = await loadSharedConfigFiles();
const profileData = ini.configFile["sdk-integ-test"];
if (profileData) {
console.log("Setting AWS_PROFILE=sdk-integ-test");
process.env.AWS_PROFILE = "sdk-integ-test";
}

try {
return await spawnProcess("yarn", command, {
stdio: "inherit",
Expand Down
20 changes: 4 additions & 16 deletions tests/e2e/get-integ-test-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,15 @@ const { S3ControlClient, ListMultiRegionAccessPointsCommand } = require("@aws-sd
const { ensureTestStack } = require("./ensure-test-stack");
const { deleteStaleChangesets } = require("./delete-stale-changesets");
const { loadSharedConfigFiles } = require("@smithy/shared-ini-file-loader");
const { createCredentialChain, fromIni, fromHttp } = require("@aws-sdk/credential-providers");

exports.getIntegTestResources = async () => {
const ini = await loadSharedConfigFiles();
const profileData = ini.configFile["sdk-integ-test"] ?? ini.credentialsFile["sdk-integ-test"];
if (profileData) {
console.log("Setting AWS_PROFILE=sdk-integ-test");
process.env.AWS_PROFILE = "sdk-integ-test";
if (profileData.role_arn) {
console.log(
`Setting AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`
);
process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = `/role-arn/${profileData.role_arn}`;
}
} else {
console.log("AWS_PROFILE is", process.env.AWS_PROFILE);
}

const region = "us-west-2";

console.log({ files: JSON.stringify(await loadSharedConfigFiles(), null, 2), ENV: process.env });

const cloudformation = new CloudFormationClient({
region,
logger: console,
});
const stackName = "SdkReleaseV3IntegTestResourcesStack";

Expand Down
1 change: 1 addition & 0 deletions vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
exclude: ["node_modules", "**/*.browser.e2e.spec.ts"],
include: ["**/*.e2e.spec.ts"],
environment: "node",
env: process.env as Record<string, string>,
},
});

0 comments on commit 8411603

Please sign in to comment.