Commit 32c50f7e authored by Shinya Maeda's avatar Shinya Maeda

Finish all tests

parent efd30ba5
...@@ -159,6 +159,17 @@ describe Projects::JobsController do ...@@ -159,6 +159,17 @@ describe Projects::JobsController do
get_trace get_trace
end end
context 'when job has a trace artifact' do
let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) }
it 'returns a trace' do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
expect(json_response['html']).to eq(job.trace.html)
end
end
context 'when job has a trace' do context 'when job has a trace' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) } let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
...@@ -381,7 +392,7 @@ describe Projects::JobsController do ...@@ -381,7 +392,7 @@ describe Projects::JobsController do
end end
context 'when job is erasable' do context 'when job is erasable' do
let(:job) { create(:ci_build, :erasable, :trace, pipeline: pipeline) } let(:job) { create(:ci_build, :erasable, :trace, :trace_artifact, pipeline: pipeline) }
it 'redirects to the erased job page' do it 'redirects to the erased job page' do
expect(response).to have_gitlab_http_status(:found) expect(response).to have_gitlab_http_status(:found)
...@@ -439,6 +450,16 @@ describe Projects::JobsController do ...@@ -439,6 +450,16 @@ describe Projects::JobsController do
get_raw get_raw
end end
context 'when job has a trace artifact' do
let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) }
it 'returns a trace' do
expect(response).to have_gitlab_http_status(:ok)
expect(response.content_type).to eq 'text/plain; charset=utf-8'
expect(response.body).to eq job.job_artifacts_trace.open.read
end
end
context 'when job has a trace file' do context 'when job has a trace file' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) } let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
......
...@@ -272,13 +272,13 @@ feature 'Jobs' do ...@@ -272,13 +272,13 @@ feature 'Jobs' do
end end
feature 'HTML trace', :js do feature 'HTML trace', :js do
context 'when job is running' do
before do before do
job.run! job.run!
visit project_job_path(project, job) visit project_job_path(project, job)
end end
context 'when job has an initial trace' do
it 'loads job trace' do it 'loads job trace' do
expect(page).to have_content 'BUILD TRACE' expect(page).to have_content 'BUILD TRACE'
...@@ -490,6 +490,7 @@ feature 'Jobs' do ...@@ -490,6 +490,7 @@ feature 'Jobs' do
describe 'GET /:project/jobs/:id/raw', :js do describe 'GET /:project/jobs/:id/raw', :js do
context 'access source' do context 'access source' do
context 'job from project' do context 'job from project' do
context 'when job is running' do
before do before do
job.run! job.run!
end end
...@@ -505,6 +506,21 @@ feature 'Jobs' do ...@@ -505,6 +506,21 @@ feature 'Jobs' do
end end
end end
context 'when job is complete' do
let(:job) { create(:ci_build, :success, :trace_artifact, pipeline: pipeline) }
it 'sends the right headers' do
requests = inspect_requests(inject_headers: { 'X-Sendfile-Type' => 'X-Sendfile' }) do
visit raw_project_job_path(project, job)
end
expect(requests.first.status_code).to eq(200)
expect(requests.first.response_headers['Content-Type']).to eq('text/plain; charset=utf-8')
expect(requests.first.response_headers['X-Sendfile']).to eq(job.job_artifacts_trace.file.path)
end
end
end
context 'job from other project' do context 'job from other project' do
before do before do
job2.run! job2.run!
......
...@@ -675,7 +675,7 @@ describe Ci::Build do ...@@ -675,7 +675,7 @@ describe Ci::Build do
context 'build is erasable' do context 'build is erasable' do
context 'new artifacts' do context 'new artifacts' do
let!(:build) { create(:ci_build, :trace, :success, :artifacts) } let!(:build) { create(:ci_build, :trace, :trace_artifact, :success, :artifacts) }
describe '#erase' do describe '#erase' do
before do before do
...@@ -709,7 +709,7 @@ describe Ci::Build do ...@@ -709,7 +709,7 @@ describe Ci::Build do
end end
describe '#erased?' do describe '#erased?' do
let!(:build) { create(:ci_build, :trace, :success, :artifacts) } let!(:build) { create(:ci_build, :trace, :trace_artifact, :success, :artifacts) }
subject { build.erased? } subject { build.erased? }
context 'job has not been erased' do context 'job has not been erased' do
......
...@@ -446,18 +446,29 @@ describe API::Jobs do ...@@ -446,18 +446,29 @@ describe API::Jobs do
end end
describe 'GET /projects/:id/jobs/:job_id/trace' do describe 'GET /projects/:id/jobs/:job_id/trace' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
before do before do
get api("/projects/#{project.id}/jobs/#{job.id}/trace", api_user) get api("/projects/#{project.id}/jobs/#{job.id}/trace", api_user)
end end
context 'authorized user' do context 'authorized user' do
context 'when trace is artifact' do
let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) }
it 'returns specific job trace' do
expect(response).to have_gitlab_http_status(200)
expect(response.body).to eq(job.trace.raw)
end
end
context 'when trace is file' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
it 'returns specific job trace' do it 'returns specific job trace' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.body).to eq(job.trace.raw) expect(response.body).to eq(job.trace.raw)
end end
end end
end
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
...@@ -543,11 +554,11 @@ describe API::Jobs do ...@@ -543,11 +554,11 @@ describe API::Jobs do
end end
context 'job is erasable' do context 'job is erasable' do
let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) } let(:job) { create(:ci_build, :trace, :trace_artifact, :artifacts, :success, project: project, pipeline: pipeline) }
it 'erases job content' do it 'erases job content' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(job).not_to have_trace expect(job.trace.exist?).to be_falsy
expect(job.artifacts_file.exists?).to be_falsy expect(job.artifacts_file.exists?).to be_falsy
expect(job.artifacts_metadata.exists?).to be_falsy expect(job.artifacts_metadata.exists?).to be_falsy
end end
...@@ -570,7 +581,7 @@ describe API::Jobs do ...@@ -570,7 +581,7 @@ describe API::Jobs do
context 'when a developer erases a build' do context 'when a developer erases a build' do
let(:role) { :developer } let(:role) { :developer }
let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline, user: owner) } let(:job) { create(:ci_build, :trace, :trace_artifact, :artifacts, :success, project: project, pipeline: pipeline, user: owner) }
context 'when the build was created by the developer' do context 'when the build was created by the developer' do
let(:owner) { user } let(:owner) { user }
......
...@@ -680,11 +680,17 @@ describe API::Runner do ...@@ -680,11 +680,17 @@ describe API::Runner do
end end
context 'when tace is given' do context 'when tace is given' do
it 'updates a running build' do it 'creates a trace artifact' do
update_job(trace: 'BUILD TRACE UPDATED') allow_any_instance_of(BuildFinishedWorker).to receive(:perform).with(job.id) do
CreateTraceArtifactWorker.new.perform(job.id)
end
update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
job.reload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(job.reload.trace.raw).to eq 'BUILD TRACE UPDATED' expect(job.trace.raw).to eq 'BUILD TRACE UPDATED'
expect(job.job_artifacts_trace.open.read).to eq 'BUILD TRACE UPDATED'
end end
end end
......
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