@@ -31,7 +31,7 @@ const mockOctokit = {
31
31
const mockCreateRunner = mocked ( createRunner ) ;
32
32
const mockListRunners = mocked ( listEC2Runners ) ;
33
33
const mockSSMClient = mockClient ( SSMClient ) ;
34
- const mockSSM = mocked ( getParameter ) ;
34
+ const mockSSMgetParameter = mocked ( getParameter ) ;
35
35
36
36
jest . mock ( '@octokit/rest' , ( ) => ( {
37
37
Octokit : jest . fn ( ) . mockImplementation ( ( ) => mockOctokit ) ,
@@ -85,6 +85,7 @@ let expectedRunnerParams: RunnerInputParameters;
85
85
86
86
function setDefaults ( ) {
87
87
process . env = { ...cleanEnv } ;
88
+ process . env . PARAMETER_GITHUB_APP_ID_NAME = 'github-app-id' ;
88
89
process . env . GITHUB_APP_KEY_BASE64 = 'TEST_CERTIFICATE_DATA' ;
89
90
process . env . GITHUB_APP_ID = '1337' ;
90
91
process . env . GITHUB_APP_CLIENT_ID = 'TEST_CLIENT_ID' ;
@@ -104,52 +105,9 @@ beforeEach(() => {
104
105
jest . clearAllMocks ( ) ;
105
106
setDefaults ( ) ;
106
107
107
- mockOctokit . actions . getJobForWorkflowRun . mockImplementation ( ( ) => ( {
108
- data : {
109
- status : 'queued' ,
110
- } ,
111
- } ) ) ;
112
- mockOctokit . paginate . mockImplementation ( ( ) => [
113
- {
114
- id : 1 ,
115
- name : 'Default' ,
116
- } ,
117
- ] ) ;
118
- mockOctokit . actions . generateRunnerJitconfigForOrg . mockImplementation ( ( ) => ( {
119
- data : {
120
- encoded_jit_config : 'TEST_JIT_CONFIG_ORG' ,
121
- } ,
122
- } ) ) ;
123
- mockOctokit . actions . generateRunnerJitconfigForRepo . mockImplementation ( ( ) => ( {
124
- data : {
125
- encoded_jit_config : 'TEST_JIT_CONFIG_REPO' ,
126
- } ,
127
- } ) ) ;
128
- mockOctokit . checks . get . mockImplementation ( ( ) => ( {
129
- data : {
130
- status : 'queued' ,
131
- } ,
132
- } ) ) ;
133
- const mockTokenReturnValue = {
134
- data : {
135
- token : '1234abcd' ,
136
- } ,
137
- } ;
138
- const mockInstallationIdReturnValueOrgs = {
139
- data : {
140
- id : TEST_DATA . installationId ,
141
- } ,
142
- } ;
143
- const mockInstallationIdReturnValueRepos = {
144
- data : {
145
- id : TEST_DATA . installationId ,
146
- } ,
147
- } ;
108
+ defaultSSMGetParameterMockImpl ( ) ;
109
+ defaultOctokitMockImpl ( ) ;
148
110
149
- mockOctokit . actions . createRegistrationTokenForOrg . mockImplementation ( ( ) => mockTokenReturnValue ) ;
150
- mockOctokit . actions . createRegistrationTokenForRepo . mockImplementation ( ( ) => mockTokenReturnValue ) ;
151
- mockOctokit . apps . getOrgInstallation . mockImplementation ( ( ) => mockInstallationIdReturnValueOrgs ) ;
152
- mockOctokit . apps . getRepoInstallation . mockImplementation ( ( ) => mockInstallationIdReturnValueRepos ) ;
153
111
mockCreateRunner . mockImplementation ( async ( ) => {
154
112
return [ 'i-12345' ] ;
155
113
} ) ;
@@ -180,10 +138,6 @@ beforeEach(() => {
180
138
} ) ;
181
139
182
140
mockCreateClient . mockResolvedValue ( new mocktokit ( ) ) ;
183
-
184
- mockSSM . mockImplementation ( async ( ) => {
185
- return '1' ;
186
- } ) ;
187
141
} ) ;
188
142
189
143
describe ( 'scaleUp with GHES' , ( ) => {
@@ -281,7 +235,7 @@ describe('scaleUp with GHES', () => {
281
235
282
236
it ( 'Throws an error if runner group doesnt exist for ephemeral runners' , async ( ) => {
283
237
process . env . RUNNER_GROUP_NAME = 'test-runner-group' ;
284
- mockSSM . mockImplementation ( async ( ) => {
238
+ mockSSMgetParameter . mockImplementation ( async ( ) => {
285
239
throw new Error ( 'ParameterNotFound' ) ;
286
240
} ) ;
287
241
await expect ( scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ) . rejects . toBeInstanceOf ( Error ) ;
@@ -297,7 +251,7 @@ describe('scaleUp with GHES', () => {
297
251
} ) ;
298
252
299
253
it ( 'create SSM parameter for runner group id if it doesnt exist' , async ( ) => {
300
- mockSSM . mockImplementation ( async ( ) => {
254
+ mockSSMgetParameter . mockImplementation ( async ( ) => {
301
255
throw new Error ( 'ParameterNotFound' ) ;
302
256
} ) ;
303
257
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
@@ -318,6 +272,7 @@ describe('scaleUp with GHES', () => {
318
272
319
273
it ( 'create start runner config for ephemeral runners ' , async ( ) => {
320
274
process . env . RUNNERS_MAXIMUM_COUNT = '2' ;
275
+
321
276
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
322
277
expect ( mockOctokit . actions . generateRunnerJitconfigForOrg ) . toBeCalledWith ( {
323
278
org : TEST_DATA . repositoryOwner ,
@@ -719,3 +674,65 @@ describe('scaleUp with public GH', () => {
719
674
} ) ;
720
675
} ) ;
721
676
} ) ;
677
+
678
+ function defaultOctokitMockImpl ( ) {
679
+ mockOctokit . actions . getJobForWorkflowRun . mockImplementation ( ( ) => ( {
680
+ data : {
681
+ status : 'queued' ,
682
+ } ,
683
+ } ) ) ;
684
+ mockOctokit . paginate . mockImplementation ( ( ) => [
685
+ {
686
+ id : 1 ,
687
+ name : 'Default' ,
688
+ } ,
689
+ ] ) ;
690
+ mockOctokit . actions . generateRunnerJitconfigForOrg . mockImplementation ( ( ) => ( {
691
+ data : {
692
+ encoded_jit_config : 'TEST_JIT_CONFIG_ORG' ,
693
+ } ,
694
+ } ) ) ;
695
+ mockOctokit . actions . generateRunnerJitconfigForRepo . mockImplementation ( ( ) => ( {
696
+ data : {
697
+ encoded_jit_config : 'TEST_JIT_CONFIG_REPO' ,
698
+ } ,
699
+ } ) ) ;
700
+ mockOctokit . checks . get . mockImplementation ( ( ) => ( {
701
+ data : {
702
+ status : 'queued' ,
703
+ } ,
704
+ } ) ) ;
705
+
706
+ const mockTokenReturnValue = {
707
+ data : {
708
+ token : '1234abcd' ,
709
+ } ,
710
+ } ;
711
+ const mockInstallationIdReturnValueOrgs = {
712
+ data : {
713
+ id : TEST_DATA . installationId ,
714
+ } ,
715
+ } ;
716
+ const mockInstallationIdReturnValueRepos = {
717
+ data : {
718
+ id : TEST_DATA . installationId ,
719
+ } ,
720
+ } ;
721
+
722
+ mockOctokit . actions . createRegistrationTokenForOrg . mockImplementation ( ( ) => mockTokenReturnValue ) ;
723
+ mockOctokit . actions . createRegistrationTokenForRepo . mockImplementation ( ( ) => mockTokenReturnValue ) ;
724
+ mockOctokit . apps . getOrgInstallation . mockImplementation ( ( ) => mockInstallationIdReturnValueOrgs ) ;
725
+ mockOctokit . apps . getRepoInstallation . mockImplementation ( ( ) => mockInstallationIdReturnValueRepos ) ;
726
+ }
727
+
728
+ function defaultSSMGetParameterMockImpl ( ) {
729
+ mockSSMgetParameter . mockImplementation ( async ( name : string ) => {
730
+ if ( name === `${ process . env . SSM_CONFIG_PATH } /runner-group/${ process . env . RUNNER_GROUP_NAME } ` ) {
731
+ return '1' ;
732
+ } else if ( name === `${ process . env . PARAMETER_GITHUB_APP_ID_NAME } ` ) {
733
+ return `${ process . env . GITHUB_APP_ID } ` ;
734
+ } else {
735
+ throw new Error ( `ParameterNotFound: ${ name } ` ) ;
736
+ }
737
+ } ) ;
738
+ }
0 commit comments