From 8a5b8d9e686ab312d0a9138e8b94420c4d171a26 Mon Sep 17 00:00:00 2001 From: Roger Zhang Date: Wed, 16 Oct 2024 10:53:35 -0700 Subject: [PATCH] test(credentials): do not modify developer $HOME #5791 ## Problem https://github.com/aws/aws-toolkit-vscode/blob/0164d4145e58ae036ddf3815455ea12a159d491d/packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts#L38-L39 This test is deleting my actual aws config file. ## Solution Update the environment variable to point to a fake location before test Then recover them after test --- .../credentials/userCredentialsUtils.test.ts | 15 ++------------- ... Fix-a0acdaa1-7356-4f58-bc9b-fb7b708fe831.json | 4 ++++ 2 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 packages/toolkit/.changes/next-release/Bug Fix-a0acdaa1-7356-4f58-bc9b-fb7b708fe831.json diff --git a/packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts b/packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts index ddbd250c2cd..eaeb9bc571d 100644 --- a/packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts +++ b/packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts @@ -18,31 +18,20 @@ import { import { UserCredentialsUtils } from '../../../shared/credentials/userCredentialsUtils' import { EnvironmentVariables } from '../../../shared/environmentVariables' import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities' -import { getConfigFilename, getCredentialsFilename } from '../../../auth/credentials/sharedCredentialsFile' import { fs } from '../../../shared' describe('UserCredentialsUtils', function () { let tempFolder: string - let defaultConfigFileName: string - let defaultCredentialsFilename: string - before(async function () { - defaultConfigFileName = getConfigFilename() - defaultCredentialsFilename = getCredentialsFilename() + beforeEach(async function () { // Make a temp folder for all these tests // Stick some temp credentials files in there to load from tempFolder = await makeTemporaryToolkitFolder() }) afterEach(async function () { - await fs.delete(defaultConfigFileName, { recursive: true }) - await fs.delete(defaultCredentialsFilename, { recursive: true }) - - sinon.restore() - }) - - after(async function () { await fs.delete(tempFolder, { recursive: true }) + sinon.restore() }) describe('findExistingCredentialsFilenames', function () { diff --git a/packages/toolkit/.changes/next-release/Bug Fix-a0acdaa1-7356-4f58-bc9b-fb7b708fe831.json b/packages/toolkit/.changes/next-release/Bug Fix-a0acdaa1-7356-4f58-bc9b-fb7b708fe831.json new file mode 100644 index 00000000000..ecefcc6e87b --- /dev/null +++ b/packages/toolkit/.changes/next-release/Bug Fix-a0acdaa1-7356-4f58-bc9b-fb7b708fe831.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Fix userCredentialsUtils.test.ts so it won't remove the actual aws config" +}