@@ -34,23 +34,6 @@ const mockRunningInstances: AWS.EC2.DescribeInstancesResult = {
34
34
} ,
35
35
] ,
36
36
} ;
37
- const mockRunningInstancesLegacy : AWS . EC2 . DescribeInstancesResult = {
38
- Reservations : [
39
- {
40
- Instances : [
41
- {
42
- LaunchTime : new Date ( '2020-10-11T14:48:00.000+09:00' ) ,
43
- InstanceId : 'i-5678' ,
44
- Tags : [
45
- { Key : 'Owner' , Value : REPO_NAME } ,
46
- { Key : 'Type' , Value : 'Repo' } ,
47
- { Key : 'Application' , Value : 'github-action-runner' } ,
48
- ] ,
49
- } ,
50
- ] ,
51
- } ,
52
- ] ,
53
- } ;
54
37
55
38
describe ( 'list instances' , ( ) => {
56
39
beforeEach ( ( ) => {
@@ -60,36 +43,27 @@ describe('list instances', () => {
60
43
61
44
it ( 'returns a list of instances' , async ( ) => {
62
45
mockDescribeInstances . promise
63
- . mockReturnValueOnce ( mockRunningInstances )
64
- . mockReturnValueOnce ( mockRunningInstancesLegacy ) ;
46
+ . mockReturnValue ( mockRunningInstances ) ;
65
47
const resp = await listEC2Runners ( ) ;
66
- expect ( resp . length ) . toBe ( 2 ) ;
48
+ expect ( resp . length ) . toBe ( 1 ) ;
67
49
expect ( resp ) . toContainEqual ( {
68
50
instanceId : 'i-1234' ,
69
51
launchTime : new Date ( '2020-10-10T14:48:00.000+09:00' ) ,
70
52
type : 'Org' ,
71
53
owner : 'CoderToCat' ,
72
54
} ) ;
73
- expect ( resp ) . toContainEqual ( {
74
- instanceId : 'i-5678' ,
75
- launchTime : new Date ( '2020-10-11T14:48:00.000+09:00' ) ,
76
- type : 'Repo' ,
77
- owner : REPO_NAME ,
78
- } ) ;
79
55
} ) ;
80
56
81
57
it ( 'calls EC2 describe instances' , async ( ) => {
82
58
mockDescribeInstances . promise
83
- . mockReturnValueOnce ( mockRunningInstances )
84
- . mockReturnValueOnce ( mockRunningInstancesLegacy ) ;
59
+ . mockReturnValueOnce ( mockRunningInstances ) ;
85
60
await listEC2Runners ( ) ;
86
61
expect ( mockEC2 . describeInstances ) . toBeCalled ( ) ;
87
62
} ) ;
88
63
89
64
it ( 'filters instances on repo name' , async ( ) => {
90
65
mockDescribeInstances . promise
91
- . mockReturnValueOnce ( mockRunningInstances )
92
- . mockReturnValueOnce ( mockRunningInstancesLegacy ) ;
66
+ . mockReturnValueOnce ( mockRunningInstances ) ;
93
67
await listEC2Runners ( { runnerType : 'Repo' , runnerOwner : REPO_NAME , environment : undefined } ) ;
94
68
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
95
69
Filters : [
@@ -99,20 +73,11 @@ describe('list instances', () => {
99
73
{ Name : 'tag:ghr:Application' , Values : [ 'github-action-runner' ] } ,
100
74
] ,
101
75
} ) ;
102
- expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
103
- Filters : [
104
- { Name : 'instance-state-name' , Values : [ 'running' , 'pending' ] } ,
105
- { Name : 'tag:Type' , Values : [ 'Repo' ] } ,
106
- { Name : 'tag:Owner' , Values : [ REPO_NAME ] } ,
107
- { Name : 'tag:Application' , Values : [ 'github-action-runner' ] } ,
108
- ] ,
109
- } ) ;
110
76
} ) ;
111
77
112
78
it ( 'filters instances on org name' , async ( ) => {
113
79
mockDescribeInstances . promise
114
- . mockReturnValueOnce ( mockRunningInstances )
115
- . mockReturnValueOnce ( mockRunningInstancesLegacy ) ;
80
+ . mockReturnValueOnce ( mockRunningInstances ) ;
116
81
await listEC2Runners ( { runnerType : 'Org' , runnerOwner : ORG_NAME , environment : undefined } ) ;
117
82
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
118
83
Filters : [
@@ -126,8 +91,7 @@ describe('list instances', () => {
126
91
127
92
it ( 'filters instances on environment' , async ( ) => {
128
93
mockDescribeInstances . promise
129
- . mockReturnValueOnce ( mockRunningInstances )
130
- . mockReturnValueOnce ( mockRunningInstancesLegacy ) ;
94
+ . mockReturnValueOnce ( mockRunningInstances ) ;
131
95
await listEC2Runners ( { environment : ENVIRONMENT } ) ;
132
96
expect ( mockEC2 . describeInstances ) . toBeCalledWith ( {
133
97
Filters : [
@@ -155,7 +119,7 @@ describe('list instances', () => {
155
119
} ,
156
120
] ,
157
121
} ;
158
- mockDescribeInstances . promise . mockReturnValueOnce ( noInstances ) . mockReturnValueOnce ( noInstances ) ;
122
+ mockDescribeInstances . promise . mockReturnValueOnce ( noInstances ) ;
159
123
const resp = await listEC2Runners ( ) ;
160
124
expect ( resp . length ) . toBe ( 0 ) ;
161
125
} ) ;
@@ -174,7 +138,7 @@ describe('list instances', () => {
174
138
} ,
175
139
] ,
176
140
} ;
177
- mockDescribeInstances . promise . mockReturnValueOnce ( noInstances ) . mockReturnValue ( { } ) ;
141
+ mockDescribeInstances . promise . mockReturnValueOnce ( noInstances ) ;
178
142
const resp = await listEC2Runners ( ) ;
179
143
expect ( resp . length ) . toBe ( 1 ) ;
180
144
} ) ;
0 commit comments