diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-11-16 17:12:33 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-11-28 00:36:48 +0100 |
commit | 623eb68195d51ea50e09970771442d992ff19a4a (patch) | |
tree | b8778abd2aabd5a80867f9250884f39b506fa861 /spec/requests/api/runners_spec.rb | |
parent | 8e7e2aeb4f0f9e1e61366a62e41fd15936593cfd (diff) | |
download | gitlab-ce-623eb68195d51ea50e09970771442d992ff19a4a.tar.gz |
Add new API endpoint - list jobs of a specified runner
Diffstat (limited to 'spec/requests/api/runners_spec.rb')
-rw-r--r-- | spec/requests/api/runners_spec.rb | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index fe38a7b3251..95e5dd91c12 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -354,6 +354,98 @@ describe API::Runners do end end + describe 'GET /runners/:id/jobs' do + let!(:job_1) { create(:ci_build) } + let!(:job_2) { create(:ci_build, :running, runner: shared_runner) } + let!(:job_3) { create(:ci_build, :failed, runner: shared_runner) } + let!(:job_4) { create(:ci_build, :running, runner: specific_runner) } + let!(:job_5) { create(:ci_build, :failed, runner: specific_runner) } + + context 'admin user' do + context 'when runner exists' do + context 'when runner is shared' do + it 'return jobs' do + get api("/runners/#{shared_runner.id}/jobs", admin) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + + expect(json_response.length).to eq(1) + expect(json_response[0]).to include('id' => job_2.id) + end + end + + context 'when runner is specific' do + it 'return jobs' do + get api("/runners/#{specific_runner.id}/jobs", admin) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + + expect(json_response.length).to eq(1) + expect(json_response[0]).to include('id' => job_4.id) + end + end + end + + context "when runner doesn't exist" do + it 'returns 404' do + get api('/runners/9999/jobs', admin) + + expect(response).to have_gitlab_http_status(404) + end + end + end + + context "runner project's administrative user" do + context 'when runner exists' do + context 'when runner is shared' do + it 'returns 403' do + get api("/runners/#{shared_runner.id}/jobs", user) + + expect(response).to have_gitlab_http_status(403) + end + end + + context 'when runner is specific' do + it 'return jobs' do + get api("/runners/#{specific_runner.id}/jobs", user) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + + expect(json_response.length).to eq(1) + expect(json_response[0]).to include('id' => job_4.id) + end + end + end + + context "when runner doesn't exist" do + it 'returns 404' do + get api('/runners/9999/jobs', user) + + expect(response).to have_gitlab_http_status(404) + end + end + end + + context 'other authorized user' do + it 'does not return jobs' do + get api("/runners/#{specific_runner.id}/jobs", user2) + + expect(response).to have_gitlab_http_status(403) + end + end + + context 'unauthorized user' do + it 'does not return jobs' do + get api("/runners/#{specific_runner.id}/jobs") + + expect(response).to have_gitlab_http_status(401) + end + end + end + describe 'GET /projects/:id/runners' do context 'authorized user with master privileges' do it "returns project's runners" do |