1
1
import { mocked } from 'ts-jest/utils' ;
2
- import { ActionRequestMessage , handle } from './handler ' ;
2
+ import { ActionRequestMessage , scaleUp } from './scale-up ' ;
3
3
4
4
import { createAppAuth } from '@octokit/auth-app' ;
5
5
import { Octokit } from '@octokit/rest' ;
@@ -30,7 +30,7 @@ const TEST_DATA: ActionRequestMessage = {
30
30
installationId : 2 ,
31
31
} ;
32
32
33
- describe ( 'handler ' , ( ) => {
33
+ describe ( 'scaleUp ' , ( ) => {
34
34
beforeEach ( ( ) => {
35
35
process . env . GITHUB_APP_KEY_BASE64 = 'TEST_CERTIFICATE_DATA' ;
36
36
process . env . GITHUB_APP_ID = '1337' ;
@@ -64,11 +64,11 @@ describe('handler', () => {
64
64
65
65
it ( 'ignores non-sqs events' , async ( ) => {
66
66
expect . assertions ( 1 ) ;
67
- expect ( handle ( 'aws:s3' , TEST_DATA ) ) . rejects . toEqual ( Error ( 'Cannot handle non-SQS events!' ) ) ;
67
+ expect ( scaleUp ( 'aws:s3' , TEST_DATA ) ) . rejects . toEqual ( Error ( 'Cannot handle non-SQS events!' ) ) ;
68
68
} ) ;
69
69
70
70
it ( 'checks queued workflows' , async ( ) => {
71
- await handle ( 'aws:sqs' , TEST_DATA ) ;
71
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
72
72
expect ( mockOctokit . actions . listRepoWorkflowRuns ) . toBeCalledWith ( {
73
73
owner : TEST_DATA . repositoryOwner ,
74
74
repo : TEST_DATA . repositoryName ,
@@ -80,7 +80,7 @@ describe('handler', () => {
80
80
mockOctokit . actions . listRepoWorkflowRuns . mockImplementation ( ( ) => ( {
81
81
data : { total_count : 0 , runners : [ ] } ,
82
82
} ) ) ;
83
- await handle ( 'aws:sqs' , TEST_DATA ) ;
83
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
84
84
expect ( listRunners ) . not . toBeCalled ( ) ;
85
85
} ) ;
86
86
@@ -90,7 +90,7 @@ describe('handler', () => {
90
90
} ) ;
91
91
92
92
it ( 'gets the current org level runners' , async ( ) => {
93
- await handle ( 'aws:sqs' , TEST_DATA ) ;
93
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
94
94
expect ( listRunners ) . toBeCalledWith ( {
95
95
environment : 'unit-test-environment' ,
96
96
repoName : undefined ,
@@ -99,20 +99,20 @@ describe('handler', () => {
99
99
100
100
it ( 'does not create a token when maximum runners has been reached' , async ( ) => {
101
101
process . env . RUNNERS_MAXIMUM_COUNT = '1' ;
102
- await handle ( 'aws:sqs' , TEST_DATA ) ;
102
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
103
103
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . not . toBeCalled ( ) ;
104
104
} ) ;
105
105
106
106
it ( 'creates a token when maximum runners has not been reached' , async ( ) => {
107
- await handle ( 'aws:sqs' , TEST_DATA ) ;
107
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
108
108
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . toBeCalled ( ) ;
109
109
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . toBeCalledWith ( {
110
110
org : TEST_DATA . repositoryOwner ,
111
111
} ) ;
112
112
} ) ;
113
113
114
114
it ( 'creates a runner with correct config' , async ( ) => {
115
- await handle ( 'aws:sqs' , TEST_DATA ) ;
115
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
116
116
expect ( createRunner ) . toBeCalledWith ( {
117
117
environment : 'unit-test-environment' ,
118
118
runnerConfig : `--url https://github.com/${ TEST_DATA . repositoryOwner } --token 1234abcd` ,
@@ -128,7 +128,7 @@ describe('handler', () => {
128
128
} ) ;
129
129
130
130
it ( 'gets the current repo level runners' , async ( ) => {
131
- await handle ( 'aws:sqs' , TEST_DATA ) ;
131
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
132
132
expect ( listRunners ) . toBeCalledWith ( {
133
133
environment : 'unit-test-environment' ,
134
134
repoName : `${ TEST_DATA . repositoryOwner } /${ TEST_DATA . repositoryName } ` ,
@@ -137,20 +137,20 @@ describe('handler', () => {
137
137
138
138
it ( 'does not create a token when maximum runners has been reached' , async ( ) => {
139
139
process . env . RUNNERS_MAXIMUM_COUNT = '1' ;
140
- await handle ( 'aws:sqs' , TEST_DATA ) ;
140
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
141
141
expect ( mockOctokit . actions . createRegistrationTokenForRepo ) . not . toBeCalled ( ) ;
142
142
} ) ;
143
143
144
144
it ( 'creates a token when maximum runners has not been reached' , async ( ) => {
145
- await handle ( 'aws:sqs' , TEST_DATA ) ;
145
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
146
146
expect ( mockOctokit . actions . createRegistrationTokenForRepo ) . toBeCalledWith ( {
147
147
owner : TEST_DATA . repositoryOwner ,
148
148
repo : TEST_DATA . repositoryName ,
149
149
} ) ;
150
150
} ) ;
151
151
152
152
it ( 'creates a runner with correct config' , async ( ) => {
153
- await handle ( 'aws:sqs' , TEST_DATA ) ;
153
+ await scaleUp ( 'aws:sqs' , TEST_DATA ) ;
154
154
expect ( createRunner ) . toBeCalledWith ( {
155
155
environment : 'unit-test-environment' ,
156
156
runnerConfig : `--url https://github.com/${ TEST_DATA . repositoryOwner } /${ TEST_DATA . repositoryName } --token 1234abcd` ,
0 commit comments