Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit a2f612a

Browse files
authored
Revert "Implement get and list methods for tasks in OPI (cloudfoundry#1892)"
This reverts commit f150687.
1 parent ddf6065 commit a2f612a

2 files changed

Lines changed: 12 additions & 89 deletions

File tree

lib/cloud_controller/opi/task_client.rb

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,12 @@ def desire_task(task, domain)
2121
end
2222
end
2323

24-
def fetch_task(guid)
25-
resp = client.get("/tasks/#{guid}")
26-
27-
return if resp.status_code == 404
28-
29-
if resp.status_code != 200
30-
raise CloudController::Errors::ApiError.new_from_details('TaskError', "response status code: #{resp.status_code}")
31-
end
32-
33-
task = JSON.parse(resp.body)
34-
task[:task_guid] = task.delete('guid')
35-
OPI.recursive_ostruct(task)
24+
def fetch_task(_)
25+
Diego::Bbs::Models::Task.new
3626
end
3727

3828
def fetch_tasks
39-
resp = client.get('/tasks')
40-
41-
if resp.status_code != 200
42-
raise CloudController::Errors::ApiError.new_from_details('TaskError', "response status code: #{resp.status_code}")
43-
end
44-
45-
tasks = JSON.parse(resp.body)
46-
tasks.each do |task|
47-
task['task_guid'] = task.delete('guid')
48-
end
49-
50-
tasks.map { |t| OPI.recursive_ostruct(t) }
29+
[]
5130
end
5231

5332
def cancel_task(guid)

spec/unit/lib/cloud_controller/opi/task_client_spec.rb

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -138,80 +138,24 @@
138138
end
139139

140140
describe 'can fetch a task' do
141-
let(:expected_body) {
142-
{ 'guid': 'foo' }.to_json
143-
}
144-
145-
before(:each) do
146-
stub_request(:get, "#{opi_url}/tasks/some-task-guid").
147-
to_return(status: 200, body: expected_body)
148-
end
149-
150-
it 'should return a parsed task' do
151-
task = client.fetch_task('some-task-guid')
152-
153-
expect(WebMock).to have_requested(:get, "#{opi_url}/tasks/some-task-guid")
154-
155-
expect(task).to eq(OpenStruct.new(task_guid: 'foo'))
156-
end
157-
158-
context 'when the task is not found' do
159-
before(:each) do
160-
stub_request(:get, "#{opi_url}/tasks/some-task-guid").
161-
to_return(status: 404)
162-
end
163-
164-
it 'should return nil' do
165-
expect(client.fetch_task('some-task-guid')).to be_nil
166-
end
141+
it 'should return a empty dummy task' do
142+
task = client.fetch_task('some-guid')
143+
expect(task).to eq(Diego::Bbs::Models::Task.new)
167144
end
168145

169-
context 'when fetching the task fails' do
170-
before(:each) do
171-
stub_request(:get, "#{opi_url}/tasks/some-task-guid").
172-
to_return(status: 500)
173-
end
174-
175-
it 'should raise an ApiError' do
176-
expect { client.fetch_task('some-task-guid') }.to raise_error(CloudController::Errors::ApiError, /response status code: 500/) do |e|
177-
expect(e.name).to eq('TaskError')
178-
end
179-
end
146+
it 'should not send any request to opi' do
147+
expect(a_request(:any, opi_url)).not_to have_been_made
180148
end
181149
end
182150

183151
describe 'can fetch all tasks' do
184-
let(:expected_body) {
185-
[{ 'guid': 'foo' }, { 'guid': 'bar' }].to_json
186-
}
187-
188-
before(:each) do
189-
stub_request(:get, "#{opi_url}/tasks").
190-
to_return(status: 200, body: expected_body)
191-
end
192-
193-
it 'should return a parsed list of tasks' do
152+
it 'should return an empty list' do
194153
tasks = client.fetch_tasks
195-
196-
expect(WebMock).to have_requested(:get, "#{opi_url}/tasks")
197-
198-
expect(tasks).to match_array([
199-
OpenStruct.new(task_guid: 'foo'),
200-
OpenStruct.new(task_guid: 'bar'),
201-
])
154+
expect(tasks).to be_empty
202155
end
203156

204-
context 'when fetching the tasks fails' do
205-
before(:each) do
206-
stub_request(:get, "#{opi_url}/tasks").
207-
to_return(status: 500)
208-
end
209-
210-
it 'should raise an ApiError' do
211-
expect { client.fetch_tasks }.to raise_error(CloudController::Errors::ApiError, /response status code: 500/) do |e|
212-
expect(e.name).to eq('TaskError')
213-
end
214-
end
157+
it 'should not send any request to opi' do
158+
expect(a_request(:any, opi_url)).not_to have_been_made
215159
end
216160
end
217161

0 commit comments

Comments
 (0)