Skip to content

Commit

Permalink
test(credentials): do not modify developer $HOME #5791
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
roger-zhangg authored Oct 16, 2024
1 parent 0164d41 commit 8a5b8d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Fix userCredentialsUtils.test.ts so it won't remove the actual aws config"
}

0 comments on commit 8a5b8d9

Please sign in to comment.