2020-04-21 15:21:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe Ci::GenerateTerraformReportsService do
|
2020-04-21 15:21:10 +00:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let_it_be(:merge_request) { create(:merge_request, :with_terraform_reports, source_project: project) }
|
|
|
|
|
|
|
|
subject { described_class.new(project, nil, id: merge_request.id) }
|
|
|
|
|
|
|
|
context 'when head pipeline has terraform reports' do
|
|
|
|
it 'returns status and data' do
|
2020-06-10 15:08:07 +00:00
|
|
|
pipeline = merge_request.head_pipeline
|
|
|
|
result = subject.execute(nil, pipeline)
|
|
|
|
|
|
|
|
pipeline.builds.each do |build|
|
|
|
|
expect(result).to match(
|
|
|
|
status: :parsed,
|
|
|
|
data: match(
|
|
|
|
a_hash_including(build.id.to_s => hash_including(
|
|
|
|
'create' => 0,
|
|
|
|
'delete' => 0,
|
|
|
|
'update' => 1,
|
|
|
|
'job_name' => build.options.dig(:artifacts, :name).to_s
|
|
|
|
))
|
|
|
|
),
|
|
|
|
key: an_instance_of(Array)
|
|
|
|
)
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when head pipeline has corrupted terraform reports' do
|
2020-06-23 12:09:20 +00:00
|
|
|
it 'returns a report with error messages' do
|
2020-04-21 15:21:10 +00:00
|
|
|
build = create(:ci_build, pipeline: merge_request.head_pipeline, project: project)
|
|
|
|
create(:ci_job_artifact, :terraform_with_corrupted_data, job: build, project: project)
|
|
|
|
|
|
|
|
result = subject.execute(nil, merge_request.head_pipeline)
|
|
|
|
|
|
|
|
expect(result).to match(
|
2020-06-23 12:09:20 +00:00
|
|
|
status: :parsed,
|
|
|
|
data: match(
|
|
|
|
a_hash_including(build.id.to_s => hash_including(
|
|
|
|
'tf_report_error' => :invalid_json_format
|
|
|
|
))
|
|
|
|
),
|
2020-04-21 15:21:10 +00:00
|
|
|
key: an_instance_of(Array)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 12:09:20 +00:00
|
|
|
|
|
|
|
context 'when head pipeline is corrupted' do
|
|
|
|
it 'returns status and error message' do
|
|
|
|
result = subject.execute(nil, nil)
|
|
|
|
|
|
|
|
expect(result).to match(
|
|
|
|
a_hash_including(
|
|
|
|
status: :error,
|
|
|
|
status_reason: 'An error occurred while fetching terraform reports.'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
|
|
|
end
|