Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/projects/jobs_controller_spec.rb')
-rw-r--r--spec/controllers/projects/jobs_controller_spec.rb125
1 files changed, 119 insertions, 6 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb
index 53d32665b0c..90ccb884927 100644
--- a/spec/controllers/projects/jobs_controller_spec.rb
+++ b/spec/controllers/projects/jobs_controller_spec.rb
@@ -527,6 +527,7 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
describe 'GET trace.json' do
before do
+ stub_feature_flags(job_log_json: true)
get_trace
end
@@ -535,8 +536,119 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
it 'returns a trace' do
expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('job/build_trace')
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
+ expect(json_response['state']).to be_present
+ expect(json_response['append']).not_to be_nil
+ expect(json_response['truncated']).not_to be_nil
+ expect(json_response['size']).to be_present
+ expect(json_response['total']).to be_present
+ expect(json_response['lines'].count).to be_positive
+ end
+ end
+
+ context 'when job has a trace' do
+ let(:job) { create(:ci_build, :trace_live, pipeline: pipeline) }
+
+ it 'returns a trace' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('job/build_trace')
+ expect(json_response['id']).to eq job.id
+ expect(json_response['status']).to eq job.status
+ expect(json_response['lines']).to eq [{ 'content' => [{ 'text' => 'BUILD TRACE' }], 'offset' => 0 }]
+ end
+ end
+
+ context 'when job has no traces' do
+ let(:job) { create(:ci_build, pipeline: pipeline) }
+
+ it 'returns no traces' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('job/build_trace')
+ expect(json_response['id']).to eq job.id
+ expect(json_response['status']).to eq job.status
+ expect(json_response['lines']).to be_nil
+ end
+ end
+
+ context 'when job has a trace with ANSI sequence and Unicode' do
+ let(:job) { create(:ci_build, :unicode_trace_live, pipeline: pipeline) }
+
+ it 'returns a trace with Unicode' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('job/build_trace')
+ expect(json_response['id']).to eq job.id
+ expect(json_response['status']).to eq job.status
+ expect(json_response['lines'].flat_map {|l| l['content'].map { |c| c['text'] } }).to include("ヾ(´༎ຶД༎ຶ`)ノ")
+ end
+ end
+
+ context 'when trace artifact is in ObjectStorage' do
+ let(:url) { 'http://object-storage/trace' }
+ let(:file_path) { expand_fixture_path('trace/sample_trace') }
+ let!(:job) { create(:ci_build, :success, :trace_artifact, pipeline: pipeline) }
+
+ before do
+ allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false }
+ allow_any_instance_of(JobArtifactUploader).to receive(:url) { url }
+ allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) }
+ end
+
+ context 'when there are no network issues' do
+ before do
+ stub_remote_url_206(url, file_path)
+
+ get_trace
+ end
+
+ 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['lines'].count).to be_positive
+ end
+ end
+
+ context 'when there is a network issue' do
+ before do
+ stub_remote_url_500(url)
+ end
+
+ it 'returns a trace' do
+ expect { get_trace }.to raise_error(Gitlab::HttpIO::FailedToGetChunkError)
+ end
+ end
+ end
+
+ def get_trace
+ get :trace,
+ params: {
+ namespace_id: project.namespace,
+ project_id: project,
+ id: job.id
+ },
+ format: :json
+ end
+ end
+
+ describe 'GET legacy trace.json' do
+ before do
+ get_trace
+ 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['state']).to be_present
+ expect(json_response['append']).not_to be_nil
+ expect(json_response['truncated']).not_to be_nil
+ expect(json_response['size']).to be_present
+ expect(json_response['total']).to be_present
expect(json_response['html']).to eq(job.trace.html)
end
end
@@ -612,12 +724,13 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end
def get_trace
- get :trace, params: {
- namespace_id: project.namespace,
- project_id: project,
- id: job.id
- },
- format: :json
+ get :trace,
+ params: {
+ namespace_id: project.namespace,
+ project_id: project,
+ id: job.id
+ },
+ format: :json
end
end