Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(canary): create an isolated workspace test #5929

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
})();
Loading