diff options
author | Luke Bennett <lbennett@gitlab.com> | 2018-08-06 10:20:05 +0000 |
---|---|---|
committer | Luke Bennett <lbennett@gitlab.com> | 2018-08-06 10:20:05 +0000 |
commit | 840d54cfcaa72924c3c4a91fb63a20eece780db2 (patch) | |
tree | 892d3e0fac1ffdc574ab0a6dca69bd7f90889ad9 /spec/serializers | |
parent | b2543977ff479e120746a9d826956b7a2cb6f463 (diff) | |
parent | 3bdab23c89cb3985074a7efaa3ac54c154836034 (diff) | |
download | gitlab-ce-840d54cfcaa72924c3c4a91fb63a20eece780db2.tar.gz |
Merge branch 'master' into 'ce-port-3959-mirroring-interface-improvements'
# Conflicts:
# locale/gitlab.pot
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/test_case_entity_spec.rb | 31 | ||||
-rw-r--r-- | spec/serializers/test_reports_comparer_entity_spec.rb | 76 | ||||
-rw-r--r-- | spec/serializers/test_reports_comparer_serializer_spec.rb | 62 | ||||
-rw-r--r-- | spec/serializers/test_suite_comparer_entity_spec.rb | 86 |
5 files changed, 257 insertions, 2 deletions
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index eb4235e3ee6..cf57776346a 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -125,7 +125,7 @@ describe PipelineSerializer do it 'verifies number of queries', :request_store do recorded = ActiveRecord::QueryRecorder.new { subject } - expect(recorded.count).to be_within(2).of(27) + expect(recorded.count).to be_within(2).of(31) expect(recorded.cached_count).to eq(0) end end @@ -144,7 +144,7 @@ describe PipelineSerializer do # pipeline. With the same ref this check is cached but if refs are # different then there is an extra query per ref # https://gitlab.com/gitlab-org/gitlab-ce/issues/46368 - expect(recorded.count).to be_within(2).of(30) + expect(recorded.count).to be_within(2).of(34) expect(recorded.cached_count).to eq(0) end end diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb new file mode 100644 index 00000000000..a55910f98bb --- /dev/null +++ b/spec/serializers/test_case_entity_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe TestCaseEntity do + include TestReportsHelper + + let(:entity) { described_class.new(test_case) } + + describe '#as_json' do + subject { entity.as_json } + + context 'when test case is success' do + let(:test_case) { create_test_case_rspec_success } + + it 'contains correct test case details' do + expect(subject[:status]).to eq('success') + expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary') + expect(subject[:execution_time]).to eq(1.11) + end + end + + context 'when test case is failed' do + let(:test_case) { create_test_case_rspec_failed } + + it 'contains correct test case details' do + expect(subject[:status]).to eq('failed') + expect(subject[:name]).to eq('Test#sum when a is 2 and b is 2 returns summary') + expect(subject[:execution_time]).to eq(2.22) + end + end + end +end diff --git a/spec/serializers/test_reports_comparer_entity_spec.rb b/spec/serializers/test_reports_comparer_entity_spec.rb new file mode 100644 index 00000000000..59c058fe368 --- /dev/null +++ b/spec/serializers/test_reports_comparer_entity_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe TestReportsComparerEntity do + include TestReportsHelper + + let(:entity) { described_class.new(comparer) } + let(:comparer) { Gitlab::Ci::Reports::TestReportsComparer.new(base_reports, head_reports) } + let(:base_reports) { Gitlab::Ci::Reports::TestReports.new } + let(:head_reports) { Gitlab::Ci::Reports::TestReports.new } + + describe '#as_json' do + subject { entity.as_json } + + context 'when head and base reports include two test suites' do + context 'when the status of head report is success' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_success) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_success) + end + + it 'contains correct compared test reports details' do + expect(subject[:status]).to eq('success') + expect(subject[:summary]).to include(total: 2, resolved: 0, failed: 0) + expect(subject[:suites].first[:name]).to eq('rspec') + expect(subject[:suites].first[:status]).to eq('success') + expect(subject[:suites].second[:name]).to eq('junit') + expect(subject[:suites].second[:status]).to eq('success') + end + end + + context 'when the status of head report is failed' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_success) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_failed) + end + + it 'contains correct compared test reports details' do + expect(subject[:status]).to eq('failed') + expect(subject[:summary]).to include(total: 2, resolved: 0, failed: 1) + expect(subject[:suites].first[:name]).to eq('rspec') + expect(subject[:suites].first[:status]).to eq('success') + expect(subject[:suites].second[:name]).to eq('junit') + expect(subject[:suites].second[:status]).to eq('failed') + end + end + + context 'when the status of head report is resolved' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_failed) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_resolved) + end + + let(:create_test_case_java_resolved) do + create_test_case_java_failed.tap do |test_case| + test_case.instance_variable_set("@status", Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS) + end + end + + it 'contains correct compared test reports details' do + expect(subject[:status]).to eq('success') + expect(subject[:summary]).to include(total: 2, resolved: 1, failed: 0) + expect(subject[:suites].first[:name]).to eq('rspec') + expect(subject[:suites].first[:status]).to eq('success') + expect(subject[:suites].second[:name]).to eq('junit') + expect(subject[:suites].second[:status]).to eq('success') + end + end + end + end +end diff --git a/spec/serializers/test_reports_comparer_serializer_spec.rb b/spec/serializers/test_reports_comparer_serializer_spec.rb new file mode 100644 index 00000000000..9ea86c0dd83 --- /dev/null +++ b/spec/serializers/test_reports_comparer_serializer_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe TestReportsComparerSerializer do + include TestReportsHelper + + let(:project) { double(:project) } + let(:serializer) { described_class.new(project: project).represent(comparer) } + let(:comparer) { Gitlab::Ci::Reports::TestReportsComparer.new(base_reports, head_reports) } + let(:base_reports) { Gitlab::Ci::Reports::TestReports.new } + let(:head_reports) { Gitlab::Ci::Reports::TestReports.new } + + describe '#to_json' do + subject { serializer.to_json } + + context 'when head and base reports include two test suites' do + context 'when the status of head report is success' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_success) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_success) + end + + it 'matches the schema' do + expect(subject).to match_schema('entities/test_reports_comparer') + end + end + + context 'when the status of head report is failed' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_success) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_failed) + end + + it 'matches the schema' do + expect(subject).to match_schema('entities/test_reports_comparer') + end + end + + context 'when the status of head report is resolved' do + before do + base_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + base_reports.get_suite('junit').add_test_case(create_test_case_java_failed) + head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success) + head_reports.get_suite('junit').add_test_case(create_test_case_java_resolved) + end + + let(:create_test_case_java_resolved) do + create_test_case_java_failed.tap do |test_case| + test_case.instance_variable_set("@status", Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS) + end + end + + it 'matches the schema' do + expect(subject).to match_schema('entities/test_reports_comparer') + end + end + end + end +end diff --git a/spec/serializers/test_suite_comparer_entity_spec.rb b/spec/serializers/test_suite_comparer_entity_spec.rb new file mode 100644 index 00000000000..f61331f53a0 --- /dev/null +++ b/spec/serializers/test_suite_comparer_entity_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe TestSuiteComparerEntity do + include TestReportsHelper + + let(:entity) { described_class.new(comparer) } + let(:comparer) { Gitlab::Ci::Reports::TestSuiteComparer.new(name, base_suite, head_suite) } + let(:name) { 'rpsec' } + let(:base_suite) { Gitlab::Ci::Reports::TestSuite.new(name) } + let(:head_suite) { Gitlab::Ci::Reports::TestSuite.new(name) } + let(:test_case_success) { create_test_case_rspec_success } + let(:test_case_failed) { create_test_case_rspec_failed } + + let(:test_case_resolved) do + create_test_case_rspec_failed.tap do |test_case| + test_case.instance_variable_set("@status", Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS) + end + end + + describe '#as_json' do + subject { entity.as_json } + + context 'when head sutie has a newly failed test case which does not exist in base' do + before do + base_suite.add_test_case(test_case_success) + head_suite.add_test_case(test_case_failed) + end + + it 'contains correct compared test suite details' do + expect(subject[:name]).to eq(name) + expect(subject[:status]).to eq('failed') + expect(subject[:summary]).to include(total: 1, resolved: 0, failed: 1) + subject[:new_failures].first.tap do |new_failure| + expect(new_failure[:status]).to eq(test_case_failed.status) + expect(new_failure[:name]).to eq(test_case_failed.name) + expect(new_failure[:execution_time]).to eq(test_case_failed.execution_time) + expect(new_failure[:system_output]).to eq(test_case_failed.system_output) + end + expect(subject[:resolved_failures]).to be_empty + expect(subject[:existing_failures]).to be_empty + end + end + + context 'when head sutie still has a failed test case which failed in base' do + before do + base_suite.add_test_case(test_case_failed) + head_suite.add_test_case(test_case_failed) + end + + it 'contains correct compared test suite details' do + expect(subject[:name]).to eq(name) + expect(subject[:status]).to eq('failed') + expect(subject[:summary]).to include(total: 1, resolved: 0, failed: 1) + expect(subject[:new_failures]).to be_empty + expect(subject[:resolved_failures]).to be_empty + subject[:existing_failures].first.tap do |existing_failure| + expect(existing_failure[:status]).to eq(test_case_failed.status) + expect(existing_failure[:name]).to eq(test_case_failed.name) + expect(existing_failure[:execution_time]).to eq(test_case_failed.execution_time) + expect(existing_failure[:system_output]).to eq(test_case_failed.system_output) + end + end + end + + context 'when head sutie has a success test case which failed in base' do + before do + base_suite.add_test_case(test_case_failed) + head_suite.add_test_case(test_case_resolved) + end + + it 'contains correct compared test suite details' do + expect(subject[:name]).to eq(name) + expect(subject[:status]).to eq('success') + expect(subject[:summary]).to include(total: 1, resolved: 1, failed: 0) + expect(subject[:new_failures]).to be_empty + subject[:resolved_failures].first.tap do |resolved_failure| + expect(resolved_failure[:status]).to eq(test_case_resolved.status) + expect(resolved_failure[:name]).to eq(test_case_resolved.name) + expect(resolved_failure[:execution_time]).to eq(test_case_resolved.execution_time) + expect(resolved_failure[:system_output]).to eq(test_case_resolved.system_output) + end + expect(subject[:existing_failures]).to be_empty + end + end + end +end |