BigW Consortium Gitlab

pipeline_metrics_worker_spec.rb 1.51 KB
Newer Older
1 2 3
require 'spec_helper'

describe PipelineMetricsWorker do
4
  let(:project) { create(:project, :repository) }
5 6 7 8 9 10

  let!(:merge_request) do
    create(:merge_request, source_project: project,
                           source_branch: pipeline.ref,
                           head_pipeline: pipeline)
  end
11 12 13 14 15 16 17 18 19 20 21

  let(:pipeline) do
    create(:ci_empty_pipeline,
           status: status,
           project: project,
           ref: 'master',
           sha: project.repository.commit('master').id,
           started_at: 1.hour.ago,
           finished_at: Time.now)
  end

22 23
  let(:status) { 'pending' }

24
  describe '#perform' do
25 26 27
    before do
      described_class.new.perform(pipeline.id)
    end
28 29 30 31 32

    context 'when pipeline is running' do
      let(:status) { 'running' }

      it 'records the build start time' do
33
        expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at)
34 35 36 37 38
      end

      it 'clears the build end time' do
        expect(merge_request.reload.metrics.latest_build_finished_at).to be_nil
      end
39 40 41 42

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
43 44 45 46 47 48
    end

    context 'when pipeline succeeded' do
      let(:status) { 'success' }

      it 'records the build end time' do
49
        expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at)
50
      end
51 52 53 54

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
55 56 57
    end
  end
end