Skip to content

Commit c044798

Browse files
authored
test(canary): create an isolated workspace test (#5929)
* test(canary): create an isolated workspace test * test(canary): set region on test clients
1 parent 1234534 commit c044798

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

tests/canary/canary-test-1.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const assert = require("assert");
2+
3+
/**
4+
* This test asserts that prior to the installation of
5+
* any \@aws-sdk modules, the core cannot be resolved.
6+
*
7+
* If the core is resolved, then the workspace is polluted.
8+
*/
9+
10+
try {
11+
require.resolve("@aws-sdk/core");
12+
throw new Error("@aws-sdk/core should not be accessible from a fresh directory outside the SDK workspace.");
13+
} catch (e) {
14+
assert.strictEqual(e.message.split("\n")[0], `Cannot find module '@aws-sdk/core'`);
15+
console.info("Workspace is isolated.");
16+
}

tests/canary/canary-test-2.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { STS } = require("@aws-sdk/client-sts");
2+
const { S3 } = require("@aws-sdk/client-s3");
3+
const { Lambda } = require("@aws-sdk/client-lambda");
4+
5+
/**
6+
* This test checks that a simple request to S3 (XML) and Lambda (JSON)
7+
* work correctly.
8+
*/
9+
10+
(async () => {
11+
const id = await new STS({
12+
region: "us-west-2",
13+
})
14+
.getCallerIdentity()
15+
.catch((e) => {
16+
console.error("Failed STS::getCallerIdentity");
17+
throw e;
18+
});
19+
console.log("STS::getCallerIdentity", id.$metadata.httpStatusCode);
20+
21+
const buckets = await new S3({
22+
region: "us-west-2",
23+
})
24+
.listBuckets()
25+
.catch((e) => {
26+
console.error("Failed S3::listBuckets");
27+
throw e;
28+
});
29+
console.log("S3::listBuckets", buckets.$metadata.httpStatusCode);
30+
31+
const functions = await new Lambda({
32+
region: "us-west-2",
33+
})
34+
.listFunctions()
35+
.catch((e) => {
36+
console.error("Failed Lambda::listFunctions");
37+
throw e;
38+
});
39+
console.log("Lambda::listFunctions", functions.$metadata.httpStatusCode);
40+
})();

tests/canary/canary.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
*
5+
* This script is a canary test.
6+
*
7+
* It creates an isolated small application to test
8+
* the latest version of the SDK published on NPM.
9+
*
10+
*/
11+
12+
const fs = require("fs");
13+
const path = require("path");
14+
const { spawnProcess } = require("../../scripts/utils/spawn-process");
15+
16+
(async () => {
17+
const jsv3_root = path.join(__dirname, "..", "..");
18+
const testWorkspace = path.join(jsv3_root, "..", "canary-aws-sdk-js-v3");
19+
20+
if (fs.existsSync(testWorkspace)) {
21+
await spawnProcess("rm", ["-rf", testWorkspace], {});
22+
}
23+
fs.mkdirSync(testWorkspace);
24+
25+
fs.writeFileSync(path.join(testWorkspace, "dir-check.js"), fs.readFileSync(path.join(__dirname, "canary-test-1.js")));
26+
await spawnProcess("node", ["dir-check.js"], {
27+
cwd: testWorkspace,
28+
});
29+
30+
await spawnProcess("npm", ["init", "-y"], { cwd: testWorkspace });
31+
await spawnProcess("npm", ["install", `@aws-sdk/client-sts@latest`], { cwd: testWorkspace });
32+
await spawnProcess("npm", ["install", `@aws-sdk/client-s3@latest`], { cwd: testWorkspace });
33+
await spawnProcess("npm", ["install", `@aws-sdk/client-lambda@latest`], { cwd: testWorkspace });
34+
35+
fs.writeFileSync(path.join(testWorkspace, "app.js"), fs.readFileSync(path.join(__dirname, "canary-test-2.js")));
36+
37+
await spawnProcess("node", ["app.js"], {
38+
cwd: testWorkspace,
39+
});
40+
})();

0 commit comments

Comments
 (0)