summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/parsers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/ci/parsers
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/ci/parsers')
-rw-r--r--spec/lib/gitlab/ci/parsers/accessibility/pa11y_spec.rb6
-rw-r--r--spec/lib/gitlab/ci/parsers/coverage/cobertura_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb85
-rw-r--r--spec/lib/gitlab/ci/parsers/test/junit_spec.rb2
4 files changed, 71 insertions, 24 deletions
diff --git a/spec/lib/gitlab/ci/parsers/accessibility/pa11y_spec.rb b/spec/lib/gitlab/ci/parsers/accessibility/pa11y_spec.rb
index 4d87e3b201a..b3edf452f36 100644
--- a/spec/lib/gitlab/ci/parsers/accessibility/pa11y_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/accessibility/pa11y_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'fast_spec_helper'
+require 'spec_helper'
-describe Gitlab::Ci::Parsers::Accessibility::Pa11y do
+RSpec.describe Gitlab::Ci::Parsers::Accessibility::Pa11y do
describe '#parse!' do
subject { described_class.new.parse!(pa11y, accessibility_report) }
@@ -108,7 +108,7 @@ describe Gitlab::Ci::Parsers::Accessibility::Pa11y do
it "sets error_message" do
expect { subject }.not_to raise_error
- expect(accessibility_report.error_message).to include('Pa11y parsing failed')
+ expect(accessibility_report.error_message).to include('JSON parsing failed')
expect(accessibility_report.errors_count).to eq(0)
expect(accessibility_report.passes_count).to eq(0)
expect(accessibility_report.scans_count).to eq(0)
diff --git a/spec/lib/gitlab/ci/parsers/coverage/cobertura_spec.rb b/spec/lib/gitlab/ci/parsers/coverage/cobertura_spec.rb
index e97544683db..08a3fbd7867 100644
--- a/spec/lib/gitlab/ci/parsers/coverage/cobertura_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/coverage/cobertura_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Ci::Parsers::Coverage::Cobertura do
+RSpec.describe Gitlab::Ci::Parsers::Coverage::Cobertura do
describe '#parse!' do
subject { described_class.new.parse!(cobertura, coverage_report) }
diff --git a/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb b/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
index fec27c0f31a..f487fccdab7 100644
--- a/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
@@ -2,39 +2,86 @@
require 'spec_helper'
-describe Gitlab::Ci::Parsers::Terraform::Tfplan do
+RSpec.describe Gitlab::Ci::Parsers::Terraform::Tfplan do
describe '#parse!' do
- let_it_be(:artifact) { create(:ci_job_artifact, :terraform) }
+ let(:artifact) { create(:ci_job_artifact, :terraform) }
let(:reports) { Gitlab::Ci::Reports::TerraformReports.new }
context 'when data is invalid' do
- context 'when there is no data' do
- it 'raises an error' do
- plan = '{}'
+ context 'when data is not a JSON file' do
+ it 'reports an invalid_json_format error' do
+ plan = 'Not a JSON file'
+
+ expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
+
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[job_id job_name job_path tf_report_error])
+ end
- expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
- described_class::TfplanParserError
+ expect(reports.plans).to match(
+ a_hash_including(
+ artifact.job.id.to_s => a_hash_including(
+ 'tf_report_error' => :invalid_json_format
+ )
+ )
)
end
end
- context 'when data is not a JSON file' do
- it 'raises an error' do
- plan = { 'create' => 0, 'update' => 1, 'delete' => 0 }.to_s
+ context 'when JSON is missing a required key' do
+ it 'reports an invalid_json_keys error' do
+ plan = '{ "wrong_key": 1 }'
+
+ expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
+
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[job_id job_name job_path tf_report_error])
+ end
- expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
- described_class::TfplanParserError
+ expect(reports.plans).to match(
+ a_hash_including(
+ artifact.job.id.to_s => a_hash_including(
+ 'tf_report_error' => :missing_json_keys
+ )
+ )
)
end
end
- context 'when JSON is missing a required key' do
- it 'raises an error' do
- plan = '{ "wrong_key": 1 }'
+ context 'when artifact is invalid' do
+ it 'reports an :unknown_error' do
+ expect { subject.parse!('{}', reports, artifact: nil) }.not_to raise_error
+
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[tf_report_error])
+ end
+
+ expect(reports.plans).to match(
+ a_hash_including(
+ 'failed_tf_plan' => a_hash_including(
+ 'tf_report_error' => :unknown_error
+ )
+ )
+ )
+ end
+ end
+
+ context 'when job is invalid' do
+ it 'reports an :unknown_error' do
+ artifact.job_id = nil
+ expect { subject.parse!('{}', reports, artifact: artifact) }.not_to raise_error
- expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
- described_class::TfplanParserError
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[tf_report_error])
+ end
+
+ expect(reports.plans).to match(
+ a_hash_including(
+ 'failed_tf_plan' => a_hash_including(
+ 'tf_report_error' => :unknown_error
+ )
+ )
)
end
end
@@ -47,7 +94,7 @@ describe Gitlab::Ci::Parsers::Terraform::Tfplan do
expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
reports.plans.each do |key, hash_value|
- expect(hash_value.keys).to match_array(%w[create delete job_name job_path update])
+ expect(hash_value.keys).to match_array(%w[create delete job_id job_name job_path update])
end
expect(reports.plans).to match(
@@ -68,7 +115,7 @@ describe Gitlab::Ci::Parsers::Terraform::Tfplan do
expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
reports.plans.each do |key, hash_value|
- expect(hash_value.keys).to match_array(%w[create delete job_name job_path update])
+ expect(hash_value.keys).to match_array(%w[create delete job_id job_name job_path update])
end
expect(reports.plans).to match(
diff --git a/spec/lib/gitlab/ci/parsers/test/junit_spec.rb b/spec/lib/gitlab/ci/parsers/test/junit_spec.rb
index 7b7ace02bba..1f497dea2bf 100644
--- a/spec/lib/gitlab/ci/parsers/test/junit_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/test/junit_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Ci::Parsers::Test::Junit do
+RSpec.describe Gitlab::Ci::Parsers::Test::Junit do
describe '#parse!' do
subject { described_class.new.parse!(junit, test_suite, args) }