Skip to content

Commit

Permalink
test cleanup (timeouts, move redis to integration tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Oct 15, 2020
1 parent 7073fa4 commit 7afe0ec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { DeployRequest, PoolConfig } from '../../lib/types';
import { CDS } from '../../lib/CDS';
import { processDeleteQueue } from '../../lib/skimmerSupport';

jest.setTimeout(7000);
jest.setTimeout(20000);
const deployMsgTest: DeployRequest = {
repos: [
{
Expand Down Expand Up @@ -93,7 +93,9 @@ test('can get a message from the deploy queue', async () => {
});

test('blocks deletes with bad usernames', async () => {
await expect(deleteOrg('hack@you.bad;wget')).rejects.toEqual(Error(`invalid characters in 'hack@you.bad;wget'`));
await expect(deleteOrg('hack@you.bad;wget')).rejects.toEqual(
Error(`invalid characters in 'hack@you.bad;wget'`)
);
});

test('allows deletes with good usernames', async () => {
Expand Down
25 changes: 25 additions & 0 deletions src/server/__tests__/unitTests/fileToLines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ describe('reads lines from file', () => {
expect(lines.length).toBe(1);
expect(lines[0]).toEqual(lineToKeep);
});

test('real world sample file', async () => {
const file = `#!/bin/bash
sfdx force:mdapi:deploy -w 5 -d mdapi/autoDashboard
sfdx shane:analytics:dataset:upload -n demo_data_df_testdrives --async -f data/analytics/demo_data_df_testdrives.csv -a DF19_Demo -m data/analytics/demo_data_df_testdrives.json
sfdx shane:analytics:dataset:upload -n demo_data_df_preped --async -f data/analytics/DemoDataDFPreped.csv -a DF19_Demo -m data/analytics/DemoDataDFPreped.json
sfdx shane:analytics:dataset:upload -n demo_data_df_service --async -f data/analytics/demo_data_df_service.csv -a DF19_Demo -m data/analytics/demo_data_df_service.json
sfdx shane:analytics:dataset:upload -n demo_data_df_trails --async -f data/analytics/demo_data_df_trails.csv -a DF19_Demo -m data/analytics/demo_data_df_trails.json
sfdx force:source:deploy -p force-app/
sfdx force:user:permset:assign -n autoforce_demo_pack
sfdx force:apex:execute -f data/scripts/setDemosetting.txt
sfdx force:data:tree:import -p data/sfdx-out/John-Plan.json
sfdx force:apex:execute -f data/scripts/setRoleCall.txt
sfdx force:apex:execute -f data/scripts/setContactOwner.txt
sfdx force:mdapi:deploy -w 5 -d mdapi/LeadDuplicate
sfdx force:apex:execute -f data/scripts/sendEmail.txt`;
await fs.writeFile(filename, file);
const lines = await fileToLines(filename);
expect(lines.length).toBe(13);
});

afterAll(async () => {
await fs.remove(filename);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const cmd3 =
'sfdx force:org:create --definitionfile config/project-scratch-def.json -s -a vol -d 1';

describe('flag type parsing', () => {
jest.setTimeout(10000);
jest.setTimeout(20000);
// test('handles create -a', async () => {
// const output = await getFlagsFromCommandHelp(cmd);
// expect(output.find(item => item.flag === '-f')).toHaveProperty('type', 'filepath');
Expand Down
2 changes: 1 addition & 1 deletion src/server/__tests__/unitTests/lineParse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const file2Length = 7;
// createdTimestamp: new Date()
// };
describe('multiOrgCorrections', () => {
jest.setTimeout(10000);
jest.setTimeout(50000);
it('works with single password command', async () => {
const lines = await filesToLines([
'./src/server/__tests__/helpers/initFiles/inputFile1',
Expand Down
21 changes: 17 additions & 4 deletions src/server/__tests__/unitTests/poolPrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,33 @@ describe('poolPrep Test', () => {
expect(await getPoolDeployCountByRepo(basePC)).toBe(10);

// remove something from it
let requests: DeployRequest[] = (await redis.lrange(poolDeployExchange, 0, -1)).map(queueItem => JSON.parse(queueItem));
const requests: DeployRequest[] = (
await redis.lrange(poolDeployExchange, 0, -1)
).map((queueItem) => JSON.parse(queueItem));

requests.splice(
requests.findIndex(req => req.repos[0].repo === basePC.repos[0].repo && req.repos[0].username === basePC.repos[0].username),
requests.findIndex(
(req) =>
req.repos[0].repo === basePC.repos[0].repo &&
req.repos[0].username === basePC.repos[0].username
),
1
);
requests.splice(
requests.findIndex(req => req.repos[0].repo === basePC.repos[0].repo && req.repos[0].username === basePC.repos[0].username),
requests.findIndex(
(req) =>
req.repos[0].repo === basePC.repos[0].repo &&
req.repos[0].username === basePC.repos[0].username
),
1
);

expect(requests.length).toBe(8);
await redis.del(poolDeployExchange);
await redis.lpush(poolDeployExchange, ...(requests as any[]).map(req => JSON.stringify(req)));
await redis.lpush(
poolDeployExchange,
...(requests as any[]).map((req) => JSON.stringify(req))
);
await preparePoolByName(basePC);
expect(await getPoolDeployCountByRepo(basePC)).toBe(10);
});
Expand Down
12 changes: 10 additions & 2 deletions src/server/lib/fileToLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const fileToLines = (filePath: string): Promise<string[]> => {
})
.on('line', (line: string) => {
line = line.trim();
if ((!line && line.length === 0) || line.startsWith('#!/bin/bash') || line.startsWith('#')) {
if (
(!line && line.length === 0) ||
line.startsWith('#!/bin/bash') ||
line.startsWith('#')
) {
return; // just ignore the meaningless stuff;
}
parsedLines.push(line);
Expand All @@ -24,7 +28,11 @@ const fileToLines = (filePath: string): Promise<string[]> => {
if (filePath.split('/').length > 3) {
// translate to base command, and if necessary, prepand the filepath to certain flag arguments
const commandMap = await getCommandsWithFileFlagsMap();
parsedLines = await Promise.all(parsedLines.map((line) => commandRewriter(filePath.split('/')[2], line, commandMap)));
parsedLines = await Promise.all(
parsedLines.map((line) =>
commandRewriter(filePath.split('/')[2], line, commandMap)
)
);
}
logger.debug(`fileToLines: Lines from ${filePath}: ${parsedLines.join(',')}`);
resolve(parsedLines.filter((line) => line !== ''));
Expand Down

0 comments on commit 7afe0ec

Please sign in to comment.