1
- import { listRunners , RunnerInfo , createRunner } from './runners' ;
2
- import { EC2 , SSM } from 'aws-sdk' ;
1
+ import { listRunners , createRunner } from './runners' ;
3
2
4
3
const mockEC2 = { describeInstances : jest . fn ( ) , runInstances : jest . fn ( ) } ;
5
4
const mockSSM = { putParameter : jest . fn ( ) } ;
@@ -8,6 +7,10 @@ jest.mock('aws-sdk', () => ({
8
7
SSM : jest . fn ( ) . mockImplementation ( ( ) => mockSSM ) ,
9
8
} ) ) ;
10
9
10
+ const ORG_NAME = 'SomeAwesomeCoder' ;
11
+ const REPO_NAME = `${ ORG_NAME } /some-amazing-library` ;
12
+ const ENVIRONMENT = 'unit-test-environment' ;
13
+
11
14
describe ( 'list instances' , ( ) => {
12
15
const mockDescribeInstances = { promise : jest . fn ( ) } ;
13
16
beforeEach ( ( ) => {
@@ -30,8 +33,8 @@ describe('list instances', () => {
30
33
LaunchTime : new Date ( '2020-10-11T14:48:00.000+09:00' ) ,
31
34
InstanceId : 'i-5678' ,
32
35
Tags : [
33
- { Key : 'Repo' , Value : 'SomeAwesomeCoder/some-amazing-library' } ,
34
- { Key : 'Org' , Value : 'SomeAwesomeCoder' } ,
36
+ { Key : 'Repo' , Value : REPO_NAME } ,
37
+ { Key : 'Org' , Value : ORG_NAME } ,
35
38
{ Key : 'Application' , Value : 'github-action-runner' } ,
36
39
] ,
37
40
} ,
@@ -54,8 +57,8 @@ describe('list instances', () => {
54
57
expect ( resp ) . toContainEqual ( {
55
58
instanceId : 'i-5678' ,
56
59
launchTime : new Date ( '2020-10-11T14:48:00.000+09:00' ) ,
57
- repo : 'SomeAwesomeCoder/some-amazing-library' ,
58
- org : 'SomeAwesomeCoder' ,
60
+ repo : REPO_NAME ,
61
+ org : ORG_NAME ,
59
62
} ) ;
60
63
} ) ;
61
64
@@ -65,46 +68,34 @@ describe('list instances', () => {
65
68
} ) ;
66
69
67
70
it ( 'filters instances on repo name' , async ( ) => {
68
- await listRunners ( { repoName : 'SomeAwesomeCoder/some-amazing-library' } ) ;
71
+ await listRunners ( { runnerType : 'Repo' , runnerOwner : REPO_NAME , environment : undefined } ) ;
69
72
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
70
73
Filters : [
71
74
{ Name : 'tag:Application' , Values : [ 'github-action-runner' ] } ,
72
75
{ Name : 'instance-state-name' , Values : [ 'running' , 'pending' ] } ,
73
- { Name : 'tag:Repo' , Values : [ 'SomeAwesomeCoder/some-amazing-library' ] } ,
76
+ { Name : 'tag:Repo' , Values : [ REPO_NAME ] } ,
74
77
] ,
75
78
} ) ;
76
79
} ) ;
77
80
78
81
it ( 'filters instances on org name' , async ( ) => {
79
- await listRunners ( { orgName : 'SomeAwesomeCoder' } ) ;
82
+ await listRunners ( { runnerType : 'Org' , runnerOwner : ORG_NAME , environment : undefined } ) ;
80
83
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
81
84
Filters : [
82
85
{ Name : 'tag:Application' , Values : [ 'github-action-runner' ] } ,
83
86
{ Name : 'instance-state-name' , Values : [ 'running' , 'pending' ] } ,
84
- { Name : 'tag:Org' , Values : [ 'SomeAwesomeCoder' ] } ,
87
+ { Name : 'tag:Org' , Values : [ ORG_NAME ] } ,
85
88
] ,
86
89
} ) ;
87
90
} ) ;
88
91
89
92
it ( 'filters instances on org name' , async ( ) => {
90
- await listRunners ( { environment : 'unit-test-environment' } ) ;
91
- expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
92
- Filters : [
93
- { Name : 'tag:Application' , Values : [ 'github-action-runner' ] } ,
94
- { Name : 'instance-state-name' , Values : [ 'running' , 'pending' ] } ,
95
- { Name : 'tag:Environment' , Values : [ 'unit-test-environment' ] } ,
96
- ] ,
97
- } ) ;
98
- } ) ;
99
-
100
- it ( 'filters instances on both org name and repo name' , async ( ) => {
101
- await listRunners ( { orgName : 'SomeAwesomeCoder' , repoName : 'SomeAwesomeCoder/some-amazing-library' } ) ;
93
+ await listRunners ( { environment : ENVIRONMENT } ) ;
102
94
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
103
95
Filters : [
104
96
{ Name : 'tag:Application' , Values : [ 'github-action-runner' ] } ,
105
97
{ Name : 'instance-state-name' , Values : [ 'running' , 'pending' ] } ,
106
- { Name : 'tag:Repo' , Values : [ 'SomeAwesomeCoder/some-amazing-library' ] } ,
107
- { Name : 'tag:Org' , Values : [ 'SomeAwesomeCoder' ] } ,
98
+ { Name : 'tag:Environment' , Values : [ ENVIRONMENT ] } ,
108
99
] ,
109
100
} ) ;
110
101
} ) ;
@@ -132,9 +123,9 @@ describe('create runner', () => {
132
123
it ( 'calls run instances with the correct config for repo' , async ( ) => {
133
124
await createRunner ( {
134
125
runnerConfig : 'bla' ,
135
- environment : 'unit-test-env' ,
136
- repoName : 'SomeAwesomeCoder/some-amazing-library ' ,
137
- orgName : undefined ,
126
+ environment : ENVIRONMENT ,
127
+ runnerType : 'Repo ' ,
128
+ runnerOwner : REPO_NAME
138
129
} ) ;
139
130
expect ( mockEC2 . runInstances ) . toBeCalledWith ( {
140
131
MaxCount : 1 ,
@@ -146,7 +137,7 @@ describe('create runner', () => {
146
137
ResourceType : 'instance' ,
147
138
Tags : [
148
139
{ Key : 'Application' , Value : 'github-action-runner' } ,
149
- { Key : 'Repo' , Value : 'SomeAwesomeCoder/some-amazing-library' } ,
140
+ { Key : 'Repo' , Value : REPO_NAME } ,
150
141
] ,
151
142
} ,
152
143
] ,
@@ -156,9 +147,9 @@ describe('create runner', () => {
156
147
it ( 'calls run instances with the correct config for org' , async ( ) => {
157
148
await createRunner ( {
158
149
runnerConfig : 'bla' ,
159
- environment : 'unit-test-env' ,
160
- repoName : undefined ,
161
- orgName : 'SomeAwesomeCoder' ,
150
+ environment : ENVIRONMENT ,
151
+ runnerType : 'Org' ,
152
+ runnerOwner : ORG_NAME ,
162
153
} ) ;
163
154
expect ( mockEC2 . runInstances ) . toBeCalledWith ( {
164
155
MaxCount : 1 ,
@@ -170,7 +161,7 @@ describe('create runner', () => {
170
161
ResourceType : 'instance' ,
171
162
Tags : [
172
163
{ Key : 'Application' , Value : 'github-action-runner' } ,
173
- { Key : 'Org' , Value : 'SomeAwesomeCoder' } ,
164
+ { Key : 'Org' , Value : ORG_NAME } ,
174
165
] ,
175
166
} ,
176
167
] ,
@@ -180,12 +171,12 @@ describe('create runner', () => {
180
171
it ( 'creates ssm parameters for each created instance' , async ( ) => {
181
172
await createRunner ( {
182
173
runnerConfig : 'bla' ,
183
- environment : 'unit-test-env' ,
184
- repoName : undefined ,
185
- orgName : 'SomeAwesomeCoder' ,
174
+ environment : ENVIRONMENT ,
175
+ runnerType : 'Org' ,
176
+ runnerOwner : ORG_NAME ,
186
177
} ) ;
187
178
expect ( mockSSM . putParameter ) . toBeCalledWith ( {
188
- Name : 'unit-test-env- i-1234' ,
179
+ Name : ` ${ ENVIRONMENT } - i-1234` ,
189
180
Value : 'bla' ,
190
181
Type : 'SecureString' ,
191
182
} ) ;
@@ -197,9 +188,9 @@ describe('create runner', () => {
197
188
} ) ;
198
189
await createRunner ( {
199
190
runnerConfig : 'bla' ,
200
- environment : 'unit-test-env' ,
201
- repoName : undefined ,
202
- orgName : 'SomeAwesomeCoder' ,
191
+ environment : ENVIRONMENT ,
192
+ runnerType : 'Org' ,
193
+ runnerOwner : ORG_NAME ,
203
194
} ) ;
204
195
expect ( mockSSM . putParameter ) . not . toBeCalled ( ) ;
205
196
} ) ;
0 commit comments