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

coverage_report_generator_spec.rb « reports « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eec218346c289a5c5ad687d27cbab5d1e9416157 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Reports::CoverageReportGenerator, factory_default: :keep do
  let_it_be(:project) { create_default(:project, :repository).freeze }
  let_it_be(:pipeline) { build(:ci_pipeline, :with_coverage_reports) }

  describe '#report' do
    subject { described_class.new(pipeline).report }

    let_it_be(:pipeline) { create(:ci_pipeline, :success) }

    shared_examples 'having a coverage report' do
      it 'returns coverage reports with collected data' do
        expected_files = [
          "auth/token.go",
          "auth/rpccredentials.go",
          "app/controllers/abuse_reports_controller.rb"
        ]

        expect(subject.files.keys).to match_array(expected_files)
      end
    end

    context 'when pipeline has multiple builds with coverage reports' do
      let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline) }
      let!(:build_golang) { create(:ci_build, :success, name: 'golang', pipeline: pipeline) }

      before do
        create(:ci_job_artifact, :cobertura, job: build_rspec)
        create(:ci_job_artifact, :coverage_gocov_xml, job: build_golang)
      end

      it_behaves_like 'having a coverage report'

      context 'and it is a child pipeline' do
        let!(:pipeline) { create(:ci_pipeline, :success, child_of: build(:ci_pipeline)) }

        it 'returns empty coverage report' do
          expect(subject).to be_empty
        end
      end
    end

    context 'when builds are retried' do
      let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', retried: true, pipeline: pipeline) }
      let!(:build_golang) { create(:ci_build, :success, name: 'golang', retried: true, pipeline: pipeline) }

      before do
        create(:ci_job_artifact, :cobertura, job: build_rspec)
        create(:ci_job_artifact, :coverage_gocov_xml, job: build_golang)
      end

      it 'does not take retried builds into account' do
        expect(subject).to be_empty
      end
    end

    context 'when pipeline does not have any builds with coverage reports' do
      it 'returns empty coverage reports' do
        expect(subject).to be_empty
      end
    end

    context 'when pipeline has child pipeline with builds that have coverage reports' do
      let!(:child_pipeline) { create(:ci_pipeline, :success, child_of: pipeline) }

      let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: child_pipeline) }
      let!(:build_golang) { create(:ci_build, :success, name: 'golang', pipeline: child_pipeline) }

      before do
        create(:ci_job_artifact, :cobertura, job: build_rspec)
        create(:ci_job_artifact, :coverage_gocov_xml, job: build_golang)
      end

      it_behaves_like 'having a coverage report'

      context 'when feature flag ci_child_pipeline_coverage_reports is disabled' do
        before do
          stub_feature_flags(ci_child_pipeline_coverage_reports: false)
        end

        it 'returns empty coverage reports' do
          expect(subject).to be_empty
        end
      end
    end

    context 'when both parent and child pipeline have builds with coverage reports' do
      let!(:child_pipeline) { create(:ci_pipeline, :success, child_of: pipeline) }

      let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline) }
      let!(:build_golang) { create(:ci_build, :success, name: 'golang', pipeline: child_pipeline) }

      before do
        create(:ci_job_artifact, :cobertura, job: build_rspec)
        create(:ci_job_artifact, :coverage_gocov_xml, job: build_golang)
      end

      it_behaves_like 'having a coverage report'
    end
  end
end