File: test_failure_history_worker_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (47 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Ci::TestFailureHistoryWorker, feature_category: :static_application_security_testing do
  describe '#perform' do
    subject(:perform) { described_class.new.perform(pipeline_id) }

    context 'when pipeline exists' do
      let(:pipeline) { create(:ci_pipeline) }
      let(:pipeline_id) { pipeline.id }

      it 'executes test failure history service' do
        expect_next_instance_of(::Ci::TestFailureHistoryService) do |service|
          expect(service).to receive(:execute)
        end

        perform
      end
    end

    context 'when pipeline does not exist' do
      let(:pipeline_id) { non_existing_record_id }

      it 'does not execute test failure history service' do
        expect(Ci::TestFailureHistoryService).not_to receive(:new)

        perform
      end
    end
  end

  include_examples 'an idempotent worker' do
    let(:pipeline) { create(:ci_pipeline) }
    let(:job_args) { [pipeline.id] }

    it 'tracks test failures' do
      # The test report has 2 test case failures
      create(:ci_build, :failed, :test_reports, pipeline: pipeline, project: pipeline.project)

      subject

      expect(Ci::UnitTest.count).to eq(2)
      expect(Ci::UnitTestFailure.count).to eq(2)
    end
  end
end