|
110 | 110 | subject.setup!
|
111 | 111 | end
|
112 | 112 |
|
113 |
| - it '#ssh' do |
114 |
| - expect(mock_ecs_client).to receive(:list_container_instances).and_return({ container_instance_arns: ['arn:123123'] }) |
115 |
| - expect(mock_ecs_client).to receive(:describe_container_instances).and_return(double(container_instances: [double(ec2_instance_id: 'i-123123')])) |
116 |
| - |
117 |
| - expect(mock_ec2_client).to receive(:describe_instances) |
118 |
| - .with(instance_ids: ['i-123123']) |
119 |
| - .and_return( |
120 |
| - double(reservations: [ |
121 |
| - double(instances: [double(public_dns_name: 'test.com')]) |
122 |
| - ]) |
123 |
| - ) |
| 113 | + context '#ssh' do |
| 114 | + it 'runs ssh on a single container instance' do |
| 115 | + expect(mock_ecs_client).to receive(:list_tasks).and_return({ task_arns: ['arn:123123'] }) |
| 116 | + expect(mock_ecs_client).to receive(:describe_tasks).and_return({ tasks: [{ container_instance_arn: 'arn:instance:123123' }] }) |
| 117 | + expect(mock_ecs_client).to receive(:describe_container_instances).and_return(double(container_instances: [double(ec2_instance_id: 'i-123123')])) |
| 118 | + |
| 119 | + expect(mock_ec2_client).to receive(:describe_instances) |
| 120 | + .with(instance_ids: ['i-123123']) |
| 121 | + .and_return( |
| 122 | + double(reservations: [ |
| 123 | + double(instances: [double(public_dns_name: 'test.com')]) |
| 124 | + ]) |
| 125 | + ) |
| 126 | + |
| 127 | + expect(Process).to receive(:fork) do |&block| |
| 128 | + block.call |
| 129 | + end |
| 130 | + expect(Process).to receive(:wait) |
| 131 | + |
| 132 | + expect_any_instance_of(EcsDeployCli::Runners::SSH).to receive(:exec).with('ssh ec2-user@test.com') |
| 133 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
| 134 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ec2_client).at_least(:once).and_return(mock_ec2_client) |
124 | 135 |
|
125 |
| - expect(Process).to receive(:fork) do |&block| |
126 |
| - block.call |
| 136 | + subject.ssh |
127 | 137 | end
|
128 |
| - expect(Process).to receive(:wait) |
129 | 138 |
|
130 |
| - expect_any_instance_of(EcsDeployCli::Runners::SSH).to receive(:exec).with('ssh ec2-user@test.com') |
131 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
132 |
| - expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ec2_client).at_least(:once).and_return(mock_ec2_client) |
| 139 | + it 'prompts which instance if there are multiple ones' do |
| 140 | + expect(mock_ecs_client).to receive(:list_tasks).and_return({ task_arns: ['arn:123123', 'arn:321321'] }) |
| 141 | + expect(mock_ecs_client).to receive(:describe_tasks).and_return( |
| 142 | + { |
| 143 | + tasks: [ |
| 144 | + { container_instance_arn: 'arn:instance:123123' }, |
| 145 | + { container_instance_arn: 'arn:instance:321321' } |
| 146 | + ] |
| 147 | + } |
| 148 | + ) |
| 149 | + expect(mock_ecs_client).to receive(:describe_container_instances).and_return( |
| 150 | + double(container_instances: [double(ec2_instance_id: 'i-123123'), double(ec2_instance_id: 'i-321321')]) |
| 151 | + ) |
| 152 | + |
| 153 | + expect(STDIN).to receive(:gets).and_return('2') |
133 | 154 |
|
134 |
| - subject.ssh |
| 155 | + expect(mock_ec2_client).to receive(:describe_instances) |
| 156 | + .with(instance_ids: ['i-321321']) |
| 157 | + .and_return( |
| 158 | + double(reservations: [ |
| 159 | + double(instances: [double(public_dns_name: 'test.com')]) |
| 160 | + ]) |
| 161 | + ) |
| 162 | + |
| 163 | + expect(Process).to receive(:fork) do |&block| |
| 164 | + block.call |
| 165 | + end |
| 166 | + expect(Process).to receive(:wait) |
| 167 | + |
| 168 | + expect_any_instance_of(EcsDeployCli::Runners::SSH).to receive(:exec).with('ssh ec2-user@test.com') |
| 169 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ecs_client).at_least(:once).and_return(mock_ecs_client) |
| 170 | + expect_any_instance_of(EcsDeployCli::Runners::Base).to receive(:ec2_client).at_least(:once).and_return(mock_ec2_client) |
| 171 | + |
| 172 | + subject.ssh |
| 173 | + end |
135 | 174 | end
|
136 | 175 |
|
137 | 176 | it '#diff' do
|
|
0 commit comments