|
6 | 6 | import assert from 'assert' |
7 | 7 | import * as sinon from 'sinon' |
8 | 8 | import { SafeEc2Instance } from '../../../shared/clients/ec2Client' |
9 | | -import { getIconCode } from '../../../awsService/ec2/utils' |
10 | | -import { DefaultAwsContext } from '../../../shared' |
| 9 | +import { getIconCode, getRemoveLinesCommand } from '../../../awsService/ec2/utils' |
| 10 | +import { DefaultAwsContext, globals } from '../../../shared' |
| 11 | +import { fs } from '../../../shared/fs/fs' |
| 12 | +import { createTestWorkspaceFolder } from '../../testUtil' |
| 13 | +import path from 'path' |
| 14 | +import { ChildProcess } from '../../../shared/utilities/processUtils' |
11 | 15 |
|
12 | 16 | describe('utils', async function () { |
13 | 17 | before(function () { |
@@ -52,4 +56,25 @@ describe('utils', async function () { |
52 | 56 | assert.strictEqual(getIconCode(stoppingInstance), 'loading~spin') |
53 | 57 | }) |
54 | 58 | }) |
| 59 | + |
| 60 | + describe('getRemoveLinesCommand', async function () { |
| 61 | + it('removes lines prefixed by pattern', async function () { |
| 62 | + const pattern = 'pattern' |
| 63 | + const lines = ['line1', 'line2 pattern', 'line3', 'line4 pattern', 'line5', 'line6 pattern', 'line7'] |
| 64 | + const expected = ['line1', 'line3', 'line5', 'line7'] |
| 65 | + const tempPath = await createTestWorkspaceFolder() |
| 66 | + const textFile = path.join(tempPath.uri.fsPath, 'test.txt') |
| 67 | + await fs.writeFile(textFile, lines.join('\n')) |
| 68 | + |
| 69 | + const [command, ...args] = getRemoveLinesCommand(pattern, textFile).split(' ') |
| 70 | + const process = new ChildProcess(command, args, { collect: true }) |
| 71 | + const result = await process.run() |
| 72 | + |
| 73 | + assert.strictEqual(result.exitCode, 0, `ChildProcess failed with error=${result.error}`) |
| 74 | + const newContent = await fs.readFileText(textFile) |
| 75 | + |
| 76 | + assert.strictEqual(newContent, expected.join('\n') + '\n') |
| 77 | + await fs.delete(tempPath.uri.fsPath, { recursive: true, force: true }) |
| 78 | + }) |
| 79 | + }) |
55 | 80 | }) |
0 commit comments