Commit 048b4469 authored by Alexis Reigel's avatar Alexis Reigel

cleanup runners api specs

parent 4b6619cf
...@@ -25,30 +25,34 @@ describe API::Runners do ...@@ -25,30 +25,34 @@ describe API::Runners do
describe 'GET /runners' do describe 'GET /runners' do
context 'authorized user' do context 'authorized user' do
it 'returns user available runners' do it 'returns response status and headers' do
get api('/runners', user) get api('/runners', user)
shared = json_response.any? { |r| r['is_shared'] }
descriptions = json_response.map { |runner| runner['description'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array end
expect(json_response[0]).to have_key('ip_address')
expect(descriptions).to contain_exactly( it 'returns user available runners' do
'Project runner', 'Two projects runner', 'Group runner' get api('/runners', user)
)
expect(shared).to be_falsey expect(json_response).to match_array [
a_hash_including('description' => 'Project runner'),
a_hash_including('description' => 'Two projects runner'),
a_hash_including('description' => 'Group runner')
]
end end
it 'filters runners by scope' do it 'filters runners by scope' do
get api('/runners?scope=active', user) create(:ci_runner, :project, :inactive, description: 'Inactive project runner', projects: [project])
get api('/runners?scope=paused', user)
shared = json_response.any? { |r| r['is_shared'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response[0]).to have_key('ip_address') expect(json_response).to match_array [
expect(shared).to be_falsey a_hash_including('description' => 'Inactive project runner')
]
end end
it 'avoids filtering if scope is invalid' do it 'avoids filtering if scope is invalid' do
...@@ -84,24 +88,22 @@ describe API::Runners do ...@@ -84,24 +88,22 @@ describe API::Runners do
describe 'GET /runners/all' do describe 'GET /runners/all' do
context 'authorized user' do context 'authorized user' do
context 'with admin privileges' do context 'with admin privileges' do
it 'returns all runners' do it 'returns response status and headers' do
get api('/runners/all', admin) get api('/runners/all', admin)
shared = json_response.any? { |r| r['is_shared'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response[0]).to have_key('ip_address')
expect(shared).to be_truthy
end
end end
context 'without admin privileges' do it 'returns all runners' do
it 'does not return runners list' do get api('/runners/all', admin)
get api('/runners/all', user)
expect(response).to have_gitlab_http_status(403) expect(json_response).to match_array [
end a_hash_including('description' => 'Project runner'),
a_hash_including('description' => 'Two projects runner'),
a_hash_including('description' => 'Group runner'),
a_hash_including('description' => 'Shared runner')
]
end end
it 'filters runners by scope' do it 'filters runners by scope' do
...@@ -118,12 +120,14 @@ describe API::Runners do ...@@ -118,12 +120,14 @@ describe API::Runners do
it 'filters runners by scope' do it 'filters runners by scope' do
get api('/runners/all?scope=specific', admin) get api('/runners/all?scope=specific', admin)
shared = json_response.any? { |r| r['is_shared'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response[0]).to have_key('ip_address') expect(json_response).to match_array [
expect(shared).to be_falsey a_hash_including('description' => 'Project runner'),
a_hash_including('description' => 'Two projects runner'),
a_hash_including('description' => 'Group runner')
]
end end
it 'avoids filtering if scope is invalid' do it 'avoids filtering if scope is invalid' do
...@@ -147,6 +151,15 @@ describe API::Runners do ...@@ -147,6 +151,15 @@ describe API::Runners do
end end
end end
context 'without admin privileges' do
it 'does not return runners list' do
get api('/runners/all', user)
expect(response).to have_gitlab_http_status(403)
end
end
end
context 'unauthorized user' do context 'unauthorized user' do
it 'does not return runners' do it 'does not return runners' do
get api('/runners') get api('/runners')
...@@ -607,26 +620,33 @@ describe API::Runners do ...@@ -607,26 +620,33 @@ describe API::Runners do
describe 'GET /projects/:id/runners' do describe 'GET /projects/:id/runners' do
context 'authorized user with maintainer privileges' do context 'authorized user with maintainer privileges' do
it "returns project's runners" do it 'returns response status and headers' do
get api("/projects/#{project.id}/runners", user) get api('/runners/all', admin)
shared = json_response.any? { |r| r['is_shared'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array end
expect(json_response[0]).to have_key('ip_address')
expect(shared).to be_truthy it 'returns all runners' do
get api("/projects/#{project.id}/runners", user)
expect(json_response).to match_array [
a_hash_including('description' => 'Project runner'),
a_hash_including('description' => 'Two projects runner'),
a_hash_including('description' => 'Shared runner')
]
end end
it 'filters runners by scope' do it 'filters runners by scope' do
get api("/projects/#{project.id}/runners?scope=specific", user) get api("/projects/#{project.id}/runners?scope=specific", user)
shared = json_response.any? { |r| r['is_shared'] }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response[0]).to have_key('ip_address') expect(json_response).to match_array [
expect(shared).to be_falsey a_hash_including('description' => 'Project runner'),
a_hash_including('description' => 'Two projects runner')
]
end end
it 'avoids filtering if scope is invalid' do it 'avoids filtering if scope is invalid' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment