Skip to content

Commit 20bed7f

Browse files
committed
add unit tests for createRunner
1 parent 2d3fa12 commit 20bed7f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

modules/runners/lambdas/scale-runners/src/scale-runners/handler.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ActionRequestMessage, handle } from './handler';
33

44
import { createAppAuth } from '@octokit/auth-app';
55
import { Octokit } from '@octokit/rest';
6-
import { listRunners } from './runners';
6+
import { listRunners, createRunner } from './runners';
77

88
jest.mock('@octokit/auth-app', () => ({
99
createAppAuth: jest.fn().mockImplementation(() => jest.fn().mockImplementation(() => ({ token: 'Blaat' }))),
@@ -37,6 +37,7 @@ describe('handler', () => {
3737
process.env.GITHUB_APP_CLIENT_ID = 'TEST_CLIENT_ID';
3838
process.env.GITHUB_APP_CLIENT_SECRET = 'TEST_CLIENT_SECRET';
3939
process.env.RUNNERS_MAXIMUM_COUNT = '3';
40+
process.env.ENVIRONMENT = 'unit-test-environment';
4041
jest.clearAllMocks();
4142
mockOctokit.actions.listRepoWorkflowRuns.mockImplementation(() => ({
4243
data: {
@@ -106,6 +107,16 @@ describe('handler', () => {
106107
org: TEST_DATA.repositoryOwner,
107108
});
108109
});
110+
111+
it('creates a runner with correct config', async () => {
112+
await handle('aws:sqs', TEST_DATA);
113+
expect(createRunner).toBeCalledWith({
114+
environment: 'unit-test-environment',
115+
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner} --token 1234abcd`,
116+
orgName: TEST_DATA.repositoryOwner,
117+
repoName: undefined,
118+
});
119+
});
109120
});
110121

111122
describe('on repo level', () => {
@@ -131,5 +142,15 @@ describe('handler', () => {
131142
repo: TEST_DATA.repositoryName,
132143
});
133144
});
145+
146+
it('creates a runner with correct config', async () => {
147+
await handle('aws:sqs', TEST_DATA);
148+
expect(createRunner).toBeCalledWith({
149+
environment: 'unit-test-environment',
150+
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName} --token 1234abcd`,
151+
orgName: undefined,
152+
repoName: `${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName}`,
153+
});
154+
});
134155
});
135156
});

modules/runners/lambdas/scale-runners/src/scale-runners/handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export const handle = async (eventSource: string, payload: ActionRequestMessage)
6060
: `Repo ${payload.repositoryOwner}/${payload.repositoryName}`
6161
} has ${currentRunners.length}/${maximumRunners} runners`,
6262
);
63-
console.log(currentRunners.length);
64-
console.log(maximumRunners);
63+
6564
if (currentRunners.length < maximumRunners) {
6665
// create token
6766
const registrationToken = enableOrgLevel

0 commit comments

Comments
 (0)