Skip to content

Commit

Permalink
test(canary): create an isolated workspace test (#5929)
Browse files Browse the repository at this point in the history
* test(canary): create an isolated workspace test

* test(canary): set region on test clients
  • Loading branch information
kuhe authored Mar 21, 2024
1 parent 1234534 commit c044798
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/canary/canary-test-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require("assert");

/**
* This test asserts that prior to the installation of
* any \@aws-sdk modules, the core cannot be resolved.
*
* If the core is resolved, then the workspace is polluted.
*/

try {
require.resolve("@aws-sdk/core");
throw new Error("@aws-sdk/core should not be accessible from a fresh directory outside the SDK workspace.");
} catch (e) {
assert.strictEqual(e.message.split("\n")[0], `Cannot find module '@aws-sdk/core'`);
console.info("Workspace is isolated.");
}
40 changes: 40 additions & 0 deletions tests/canary/canary-test-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { STS } = require("@aws-sdk/client-sts");
const { S3 } = require("@aws-sdk/client-s3");
const { Lambda } = require("@aws-sdk/client-lambda");

/**
* This test checks that a simple request to S3 (XML) and Lambda (JSON)
* work correctly.
*/

(async () => {
const id = await new STS({
region: "us-west-2",
})
.getCallerIdentity()
.catch((e) => {
console.error("Failed STS::getCallerIdentity");
throw e;
});
console.log("STS::getCallerIdentity", id.$metadata.httpStatusCode);

const buckets = await new S3({
region: "us-west-2",
})
.listBuckets()
.catch((e) => {
console.error("Failed S3::listBuckets");
throw e;
});
console.log("S3::listBuckets", buckets.$metadata.httpStatusCode);

const functions = await new Lambda({
region: "us-west-2",
})
.listFunctions()
.catch((e) => {
console.error("Failed Lambda::listFunctions");
throw e;
});
console.log("Lambda::listFunctions", functions.$metadata.httpStatusCode);
})();
40 changes: 40 additions & 0 deletions tests/canary/canary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

/**
*
* This script is a canary test.
*
* It creates an isolated small application to test
* the latest version of the SDK published on NPM.
*
*/

const fs = require("fs");
const path = require("path");
const { spawnProcess } = require("../../scripts/utils/spawn-process");

(async () => {
const jsv3_root = path.join(__dirname, "..", "..");
const testWorkspace = path.join(jsv3_root, "..", "canary-aws-sdk-js-v3");

if (fs.existsSync(testWorkspace)) {
await spawnProcess("rm", ["-rf", testWorkspace], {});
}
fs.mkdirSync(testWorkspace);

fs.writeFileSync(path.join(testWorkspace, "dir-check.js"), fs.readFileSync(path.join(__dirname, "canary-test-1.js")));
await spawnProcess("node", ["dir-check.js"], {
cwd: testWorkspace,
});

await spawnProcess("npm", ["init", "-y"], { cwd: testWorkspace });
await spawnProcess("npm", ["install", `@aws-sdk/client-sts@latest`], { cwd: testWorkspace });
await spawnProcess("npm", ["install", `@aws-sdk/client-s3@latest`], { cwd: testWorkspace });
await spawnProcess("npm", ["install", `@aws-sdk/client-lambda@latest`], { cwd: testWorkspace });

fs.writeFileSync(path.join(testWorkspace, "app.js"), fs.readFileSync(path.join(__dirname, "canary-test-2.js")));

await spawnProcess("node", ["app.js"], {
cwd: testWorkspace,
});
})();

0 comments on commit c044798

Please sign in to comment.