BigW Consortium Gitlab

expire_pipeline_cache_worker_spec.rb 1.93 KB
Newer Older
1 2
require 'spec_helper'

3
describe ExpirePipelineCacheWorker do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project) }
6
  let(:pipeline) { create(:ci_pipeline, project: project) }
7
  subject { described_class.new }
8

9
  describe '#perform' do
10
    it 'invalidates Etag caching for project pipelines path' do
11 12
      pipelines_path = "/#{project.full_path}/pipelines.json"
      new_mr_pipelines_path = "/#{project.full_path}/merge_requests/new.json"
13
      pipeline_path = "/#{project.full_path}/pipelines/#{pipeline.id}.json"
14

15 16
      expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipelines_path)
      expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(new_mr_pipelines_path)
17
      expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipeline_path)
18

19
      subject.perform(pipeline.id)
20
    end
21

22
    it 'invalidates Etag caching for merge request pipelines if pipeline runs on any commit of that source branch' do
23
      pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master')
24 25 26 27 28 29 30 31 32
      merge_request = create(:merge_request, source_project: project, source_branch: pipeline.ref)
      merge_request_pipelines_path = "/#{project.full_path}/merge_requests/#{merge_request.iid}/pipelines.json"

      allow_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch)
      expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(merge_request_pipelines_path)

      subject.perform(pipeline.id)
    end

33 34 35 36 37 38
    it "doesn't do anything if the pipeline not exist" do
      expect_any_instance_of(Gitlab::EtagCaching::Store).not_to receive(:touch)

      subject.perform(617748)
    end

39
    it 'updates the cached status for a project' do
40 41
      expect(Gitlab::Cache::Ci::ProjectPipelineStatus).to receive(:update_for_pipeline)
                                                            .with(pipeline)
42

43
      subject.perform(pipeline.id)
44
    end
45 46
  end
end