|
94 | 94 |
|
95 | 95 | context '#setup!' do
|
96 | 96 | before do
|
97 |
| - mock_ssm_client.stub_responses(:get_parameter, { |
98 |
| - parameter: { |
99 |
| - name: '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended', |
100 |
| - type: 'String', |
101 |
| - value: '{"schema_version":1,"image_name":"amzn2-ami-ecs-hvm-2.0.20210331-x86_64-ebs","image_id":"ami-03bbf53329af34379","os":"Amazon Linux 2","ecs_runtime_version":"Docker version 19.03.13-ce","ecs_agent_version":"1.51.0"}' |
102 |
| - } |
103 |
| - }) |
| 97 | + mock_ssm_client.stub_responses( |
| 98 | + :get_parameter, { |
| 99 | + parameter: { |
| 100 | + name: '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended', |
| 101 | + type: 'String', |
| 102 | + value: '{"schema_version":1,"image_name":"amzn2-ami-ecs-hvm-2.0.20210331-x86_64-ebs","image_id":"ami-03bbf53329af34379","os":"Amazon Linux 2","ecs_runtime_version":"Docker version 19.03.13-ce","ecs_agent_version":"1.51.0"}' |
| 103 | + } |
| 104 | + } |
| 105 | + ) |
104 | 106 | end
|
105 | 107 |
|
106 | 108 | it 'setups the cluster correctly' do
|
|
130 | 132 | end
|
131 | 133 |
|
132 | 134 | expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:iam_client).at_least(:once).and_return(mock_iam_client)
|
133 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
134 | 135 |
|
135 | 136 | expect { subject.setup! }.to output(/IAM Role ecsInstanceRole does not exist./).to_stdout
|
136 | 137 | end
|
137 | 138 |
|
138 | 139 | it 'fails if the cluster is already there' do
|
139 |
| - expect(mock_ecs_client).to receive(:describe_clusters).and_return(clusters: [{ }]) |
| 140 | + expect(mock_ecs_client).to receive(:describe_clusters).and_return(clusters: [{}]) |
140 | 141 |
|
141 | 142 | expect(EcsDeployCli.logger).to receive(:info).at_least(:once) do |message|
|
142 | 143 | puts message
|
143 | 144 | end
|
144 | 145 |
|
145 | 146 | expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwl_client).at_least(:once).and_return(mock_cwl_client)
|
| 147 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:iam_client).at_least(:once).and_return(mock_iam_client) |
146 | 148 | expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client)
|
147 | 149 |
|
148 | 150 | expect { subject.setup! }.to output(/Cluster already created, skipping./).to_stdout
|
|
172 | 174 | expect(mock_ec2_client).to receive(:describe_instances)
|
173 | 175 | .with(instance_ids: ['i-123123'])
|
174 | 176 | .and_return(
|
175 |
| - double(reservations: [ |
176 |
| - double(instances: [double(public_dns_name: 'test.com')]) |
177 |
| - ]) |
| 177 | + double( |
| 178 | + reservations: [ |
| 179 | + double(instances: [double(public_dns_name: 'test.com')]) |
| 180 | + ] |
| 181 | + ) |
178 | 182 | )
|
179 | 183 |
|
180 | 184 | expect(Process).to receive(:fork) do |&block|
|
|
209 | 213 | .with(instance_ids: ['i-321321'])
|
210 | 214 | .and_return(
|
211 | 215 | double(reservations: [
|
212 |
| - double(instances: [double(public_dns_name: 'test.com')]) |
213 |
| - ]) |
| 216 | + double(instances: [double(public_dns_name: 'test.com')]) |
| 217 | + ]) |
214 | 218 | )
|
215 | 219 |
|
216 | 220 | expect(Process).to receive(:fork) do |&block|
|
|
248 | 252 | subject.run_task!('yourproject-cron', launch_type: 'FARGATE', security_groups: [], subnets: [])
|
249 | 253 | end
|
250 | 254 |
|
251 |
| - it '#update_crons!' do |
252 |
| - mock_ecs_client.stub_responses(:register_task_definition, { task_definition: { family: 'some', revision: 1, task_definition_arn: 'arn:task:eu-central-1:xxxx' } }) |
| 255 | + context '#update_crons!' do |
| 256 | + it 'creates missing crons' do |
| 257 | + mock_ecs_client.stub_responses(:register_task_definition, { task_definition: { family: 'some', revision: 1, task_definition_arn: 'arn:task:eu-central-1:xxxx' } }) |
253 | 258 |
|
254 |
| - mock_cwe_client.stub_responses(:list_targets_by_rule, { targets: [{ id: '123', arn: 'arn:123' }] }) |
| 259 | + expect(mock_cwe_client).to receive(:list_targets_by_rule) do |
| 260 | + raise Aws::CloudWatchEvents::Errors::ResourceNotFoundException.new(nil, 'some') |
| 261 | + end |
255 | 262 |
|
256 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwl_client).at_least(:once).and_return(mock_cwl_client) |
257 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
258 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwe_client).at_least(:once).and_return(mock_cwe_client) |
| 263 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwl_client).at_least(:once).and_return(mock_cwl_client) |
| 264 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
| 265 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwe_client).at_least(:once).and_return(mock_cwe_client) |
| 266 | + |
| 267 | + subject.update_crons! |
| 268 | + end |
| 269 | + |
| 270 | + it 'updates existing crons' do |
| 271 | + mock_ecs_client.stub_responses(:register_task_definition, { task_definition: { family: 'some', revision: 1, task_definition_arn: 'arn:task:eu-central-1:xxxx' } }) |
| 272 | + |
| 273 | + mock_cwe_client.stub_responses(:list_targets_by_rule, { targets: [{ id: '123', arn: 'arn:123' }] }) |
259 | 274 |
|
260 |
| - subject.update_crons! |
| 275 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwl_client).at_least(:once).and_return(mock_cwl_client) |
| 276 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
| 277 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:cwe_client).at_least(:once).and_return(mock_cwe_client) |
| 278 | + |
| 279 | + subject.update_crons! |
| 280 | + end |
261 | 281 | end
|
262 | 282 |
|
263 | 283 | it '#update_services!' do
|
|
0 commit comments