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