summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/reports/test_reports_comparer_spec.rb
blob: 48eef0643b25d3bfad5eb54e4be50aca304a792f (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Reports::TestReportsComparer do
  include TestReportsHelper

  let(:comparer) { described_class.new(base_reports, head_reports) }
  let(:base_reports) { Gitlab::Ci::Reports::TestReports.new }
  let(:head_reports) { Gitlab::Ci::Reports::TestReports.new }

  describe '#suite_comparers' do
    subject { comparer.suite_comparers }

    context 'when head and base reports include two test suites' 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 'returns test suite comparers with specified values' do
        expect(subject[0]).to be_a(Gitlab::Ci::Reports::TestSuiteComparer)
        expect(subject[0].name).to eq('rspec')
        expect(subject[0].head_suite).to eq(head_reports.get_suite('rspec'))
        expect(subject[0].base_suite).to eq(base_reports.get_suite('rspec'))
        expect(subject[1]).to be_a(Gitlab::Ci::Reports::TestSuiteComparer)
        expect(subject[1].name).to eq('junit')
        expect(subject[1].head_suite).to eq(head_reports.get_suite('junit'))
        expect(subject[1].base_suite).to eq(base_reports.get_suite('junit'))
      end
    end
  end

  describe '#total_status' do
    subject { comparer.total_status }

    context 'when all tests cases are success in head suites' do
      before do
        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 'returns the total status' do
        is_expected.to eq(Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS)
      end
    end

    context 'when there is a failed test case in head suites' do
      before do
        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 'returns the total status in head suite' do
        is_expected.to eq(Gitlab::Ci::Reports::TestCase::STATUS_FAILED)
      end
    end
  end

  describe '#total_count' do
    subject { comparer.total_count }

    before do
      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 'returns the total test counts in head suites' do
      is_expected.to eq(2)
    end
  end

  describe '#resolved_count' do
    subject { comparer.resolved_count }

    context 'when there is a resolved test case in head suites' 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_success)
      end

      it 'returns the correct count' do
        is_expected.to eq(1)
      end
    end

    context 'when there are no resolved test cases in head suites' 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_failed)
      end

      it 'returns the correct count' do
        is_expected.to eq(0)
      end
    end
  end

  describe '#failed_count' do
    subject { comparer.failed_count }

    context 'when there is a failed test case in head suites' do
      before do
        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 'returns the correct count' do
        is_expected.to eq(1)
      end
    end

    context 'when there are no failed test cases in head suites' do
      before do
        head_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success)
        head_reports.get_suite('junit').add_test_case(create_test_case_rspec_success)
      end

      it 'returns the correct count' do
        is_expected.to eq(0)
      end
    end
  end
end