Skip to content

Commit b0d1823

Browse files
committed
adjust test cases
1 parent 22e1d1a commit b0d1823

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/core/src/awsService/ec2/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ export function getEc2SsmEnv(
5353
* @returns bash command to remove lines from file.
5454
*/
5555
export function getRemoveLinesCommand(hintComment: string, filepath: string): string {
56-
return `sed /${hintComment}/d ${filepath}`
56+
return `sed -i '' /${hintComment}/d ${filepath}`
5757
}

packages/core/src/test/awsService/ec2/utils.test.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import assert from 'assert'
77
import * as sinon from 'sinon'
88
import { SafeEc2Instance } from '../../../shared/clients/ec2Client'
99
import { getIconCode, getRemoveLinesCommand } from '../../../awsService/ec2/utils'
10-
import { DefaultAwsContext, globals } from '../../../shared'
10+
import { DefaultAwsContext } from '../../../shared'
1111
import { fs } from '../../../shared/fs/fs'
1212
import { createTestWorkspaceFolder } from '../../testUtil'
1313
import path from 'path'
@@ -58,23 +58,35 @@ describe('utils', async function () {
5858
})
5959

6060
describe('getRemoveLinesCommand', async function () {
61+
let tempPath: { uri: { fsPath: string } }
62+
63+
before(async function () {
64+
tempPath = await createTestWorkspaceFolder()
65+
})
66+
67+
after(async function () {
68+
await fs.delete(tempPath.uri.fsPath, { recursive: true, force: true })
69+
})
70+
6171
it('removes lines prefixed by pattern', async function () {
62-
const pattern = 'pattern'
6372
const lines = ['line1', 'line2 pattern', 'line3', 'line4 pattern', 'line5', 'line6 pattern', 'line7']
6473
const expected = ['line1', 'line3', 'line5', 'line7']
65-
const tempPath = await createTestWorkspaceFolder()
74+
75+
const lineToStr = (ls: string[]) => ls.join('\n') + '\n'
76+
6677
const textFile = path.join(tempPath.uri.fsPath, 'test.txt')
67-
await fs.writeFile(textFile, lines.join('\n'))
78+
const originalContent = lineToStr(lines)
79+
await fs.writeFile(textFile, originalContent)
6880

69-
const [command, ...args] = getRemoveLinesCommand(pattern, textFile).split(' ')
81+
const [command, ...args] = getRemoveLinesCommand('pattern', textFile).split(' ')
7082
const process = new ChildProcess(command, args, { collect: true })
7183
const result = await process.run()
7284

7385
assert.strictEqual(result.exitCode, 0, `ChildProcess failed with error=${result.error}`)
74-
const newContent = await fs.readFileText(textFile)
7586

76-
assert.strictEqual(newContent, expected.join('\n') + '\n')
77-
await fs.delete(tempPath.uri.fsPath, { recursive: true, force: true })
87+
const newContent = await fs.readFileText(textFile)
88+
assert.notStrictEqual(newContent, originalContent)
89+
assert.strictEqual(newContent, lineToStr(expected))
7890
})
7991
})
8092
})

0 commit comments

Comments
 (0)