ecs-rails 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28b6dcfb2734b269fbb5da27e70b0e7b43e63cbfb025f904724f804108b21573
4
- data.tar.gz: 47e6dc119ec99803eb887f8f1170e6766c28f7c086cbc1b22e7fbdc6d01c6323
3
+ metadata.gz: 17f65165aa5cdd39910dbbd8c5fe33fa9efdbb35d84d997eeb2a614ee60d799e
4
+ data.tar.gz: f1e47bc8be3542a5bf9373772fc4e9c58bff9b407c01096dd5a428d8f4f151b5
5
5
  SHA512:
6
- metadata.gz: 726c40bafbb598ce2673eeaf48b075b12ddd8f79a0fcdaba2c00c3a2c0acf953508d3783495dc6087fa520f73e4895c8733fb6f85caed5807306a7f97cdcacc7
7
- data.tar.gz: e474ae8db2e7eb9b660c5a81e9dd9a76524cc769a50d56b45843b3b30fc65ef55773165552c5c726be704d8b722b3c57dd52bac68b79cad774b1fc17626431ef
6
+ metadata.gz: c89cb54ab55232008edd3f87065e9b343c3a0a145af97b828e4139d68b2f92fe799792f04d73854c23457c312f60d4c4072c7b47a05e98fcca1bb773866ea2d0
7
+ data.tar.gz: 85a65061e5a6cce28457471579e09bf3e4aabb47ef13f05130bb7d51f703982874a0e4e96555af038075595b72139b38513920635cbd3428f187462bd66b7a2c
@@ -1,6 +1,5 @@
1
1
  module EcsRails
2
2
  class TaskSelector
3
-
4
3
  def initialize(client, cluster_name, service_name)
5
4
  @client = client
6
5
  @cluster_name = cluster_name
@@ -13,7 +12,8 @@ module EcsRails
13
12
 
14
13
  service_descriptions.each do |service|
15
14
  service.deployments.each do |deployment|
16
- task_arns = client.list_tasks(cluster: cluster_name, service_name: service.service_name, desired_status: 'RUNNING').task_arns
15
+ task_arns = client.list_tasks(cluster: cluster_name, service_name: service.service_name,
16
+ desired_status: 'RUNNING').task_arns
17
17
  next if task_arns.empty?
18
18
 
19
19
  tasks = client.describe_tasks(cluster: cluster_name, tasks: task_arns).tasks
@@ -22,12 +22,12 @@ module EcsRails
22
22
  tasks_for_deployment = tasks.select { |task| task.task_definition_arn == deployment.task_definition }
23
23
 
24
24
  if tasks_for_deployment.empty?
25
- puts(" No tasks found for this deployment.")
25
+ puts(' No tasks found for this deployment.')
26
26
  elsif tasks_for_deployment.size == 1
27
27
  puts(" Task: #{task_arns.first}")
28
- return task_arns.first
28
+ return task_arns.first
29
29
  else
30
- ask_for_task(tasks_for_deployment)
30
+ return ask_for_task(tasks_for_deployment)
31
31
  end
32
32
  end
33
33
  end
@@ -35,13 +35,13 @@ module EcsRails
35
35
 
36
36
  private
37
37
 
38
- attr_reader :client, :cluster_name, :service_name
38
+ attr_reader :client, :cluster_name, :service_name
39
39
 
40
- def ask_for_task(tasks)
41
- prompt = TTY::Prompt.new
42
- choices = tasks.map { |task| task.split('/').last }
43
- choice = prompt.enum_select("Select a task:", choices)
44
- tasks.grep(Regexp.new(choice)).first
45
- end
40
+ def ask_for_task(tasks)
41
+ prompt = TTY::Prompt.new
42
+ choices = tasks.map { |task| task.task_arn.split('/').last }
43
+ choice = prompt.enum_select('Select a task:', choices)
44
+ tasks.find { |task| task.task_arn.include?(choice) }.task_arn
45
+ end
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EcsRails
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe EcsRails::TaskSelector do
4
+ let(:client) { instance_double(Aws::ECS::Client) }
5
+ let(:cluster_name) { 'test-cluster' }
6
+ let(:service_name) { 'test-service' }
7
+ let(:selector) { described_class.new(client, cluster_name, service_name) }
8
+
9
+ describe '#call' do
10
+ let(:service) { instance_double(Aws::ECS::Types::Service, service_name: service_name, deployments: [deployment]) }
11
+ let(:deployment) { instance_double(Aws::ECS::Types::Deployment, task_definition: 'task-def-arn') }
12
+ let(:task_arn) { 'arn:aws:ecs:us-east-1:123456789:task/cluster/abc123' }
13
+
14
+ before do
15
+ allow(client).to receive(:describe_services)
16
+ .with(cluster: cluster_name, services: [service_name])
17
+ .and_return(instance_double(Aws::ECS::Types::DescribeServicesResponse, services: [service]))
18
+ end
19
+
20
+ context 'when there are no running tasks' do
21
+ before do
22
+ allow(client).to receive(:list_tasks)
23
+ .with(cluster: cluster_name, service_name: service_name, desired_status: 'RUNNING')
24
+ .and_return(instance_double(Aws::ECS::Types::ListTasksResponse, task_arns: []))
25
+ end
26
+
27
+ it 'does not return a task ARN' do
28
+ result = selector.call
29
+ expect(result).not_to be_a(String)
30
+ end
31
+ end
32
+
33
+ context 'when there is one running task' do
34
+ let(:task) { instance_double(Aws::ECS::Types::Task, task_definition_arn: 'task-def-arn', task_arn: task_arn) }
35
+
36
+ before do
37
+ allow(client).to receive(:list_tasks)
38
+ .with(cluster: cluster_name, service_name: service_name, desired_status: 'RUNNING')
39
+ .and_return(instance_double(Aws::ECS::Types::ListTasksResponse, task_arns: [task_arn]))
40
+
41
+ allow(client).to receive(:describe_tasks)
42
+ .with(cluster: cluster_name, tasks: [task_arn])
43
+ .and_return(instance_double(Aws::ECS::Types::DescribeTasksResponse, tasks: [task]))
44
+ end
45
+
46
+ it 'returns the task ARN' do
47
+ expect(selector.call).to eq(task_arn)
48
+ end
49
+ end
50
+
51
+ context 'when there are multiple running tasks' do
52
+ let(:task_arn_1) { 'arn:aws:ecs:us-east-1:123456789:task/cluster/abc123' }
53
+ let(:task_arn_2) { 'arn:aws:ecs:us-east-1:123456789:task/cluster/def456' }
54
+ let(:task_1) { instance_double(Aws::ECS::Types::Task, task_definition_arn: 'task-def-arn', task_arn: task_arn_1) }
55
+ let(:task_2) { instance_double(Aws::ECS::Types::Task, task_definition_arn: 'task-def-arn', task_arn: task_arn_2) }
56
+ let(:prompt) { instance_double(TTY::Prompt) }
57
+
58
+ before do
59
+ allow(client).to receive(:list_tasks)
60
+ .with(cluster: cluster_name, service_name: service_name, desired_status: 'RUNNING')
61
+ .and_return(instance_double(Aws::ECS::Types::ListTasksResponse, task_arns: [task_arn_1, task_arn_2]))
62
+
63
+ allow(client).to receive(:describe_tasks)
64
+ .with(cluster: cluster_name, tasks: [task_arn_1, task_arn_2])
65
+ .and_return(instance_double(Aws::ECS::Types::DescribeTasksResponse, tasks: [task_1, task_2]))
66
+
67
+ allow(TTY::Prompt).to receive(:new).and_return(prompt)
68
+ allow(prompt).to receive(:enum_select).with('Select a task:', %w[abc123 def456]).and_return('abc123')
69
+ end
70
+
71
+ it 'prompts the user to select a task and returns the selected task ARN' do
72
+ expect(selector.call).to eq(task_arn_1)
73
+ end
74
+ end
75
+
76
+ context 'when tasks do not match the deployment task definition' do
77
+ let(:task_arn) { 'arn:aws:ecs:us-east-1:123456789:task/cluster/abc123' }
78
+ let(:task) { instance_double(Aws::ECS::Types::Task, task_definition_arn: 'different-task-def', task_arn: task_arn) }
79
+
80
+ before do
81
+ allow(client).to receive(:list_tasks)
82
+ .with(cluster: cluster_name, service_name: service_name, desired_status: 'RUNNING')
83
+ .and_return(instance_double(Aws::ECS::Types::ListTasksResponse, task_arns: [task_arn]))
84
+
85
+ allow(client).to receive(:describe_tasks)
86
+ .with(cluster: cluster_name, tasks: [task_arn])
87
+ .and_return(instance_double(Aws::ECS::Types::DescribeTasksResponse, tasks: [task]))
88
+ end
89
+
90
+ it 'does not return a task ARN' do
91
+ result = selector.call
92
+ expect(result).not_to be_a(String)
93
+ end
94
+ end
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck D'agostini
@@ -146,6 +146,7 @@ files:
146
146
  - lib/ecs-rails/task_selector.rb
147
147
  - lib/ecs-rails/version.rb
148
148
  - spec/ecs-rails/ecs_rails_configuration_spec.rb
149
+ - spec/ecs-rails/task_selector_spec.rb
149
150
  - spec/fixtures/ecs-rails.yml
150
151
  - spec/spec_helper.rb
151
152
  homepage: https://rubygems.org/gems/ecs-rails