-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(canary): create an isolated workspace test (#5929)
* test(canary): create an isolated workspace test * test(canary): set region on test clients
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
})(); |