BigW Consortium Gitlab

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

describe PipelineMetricsWorker do
4
  let(:project) { create(:project, :repository) }
5 6 7 8 9 10 11 12 13 14 15 16 17
  let!(:merge_request) { create(:merge_request, source_project: project, source_branch: pipeline.ref) }

  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

  describe '#perform' do
18 19 20
    before do
      described_class.new.perform(pipeline.id)
    end
21 22 23 24 25

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

      it 'records the build start time' do
26
        expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at)
27 28 29 30 31
      end

      it 'clears the build end time' do
        expect(merge_request.reload.metrics.latest_build_finished_at).to be_nil
      end
32 33 34 35

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
36 37 38 39 40 41
    end

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

      it 'records the build end time' do
42
        expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at)
43
      end
44 45 46 47

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
48 49 50
    end
  end
end