register_build_service_spec.rb 3.0 KB
Newer Older
K
Kamil Trzcinski 已提交
1
require 'spec_helper'
V
Valery Sizov 已提交
2 3 4 5

module Ci
  describe RegisterBuildService do
    let!(:service) { RegisterBuildService.new }
6
    let!(:gl_project) { FactoryGirl.create :empty_project }
K
Kamil Trzcinski 已提交
7
    let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
K
WIP  
Kamil Trzcinski 已提交
8
    let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit }
V
Valery Sizov 已提交
9 10 11 12
    let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
    let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }

    before do
13
      specific_runner.assign_to(gl_project.ensure_gitlab_ci_project)
D
Douwe Maan 已提交
14 15
    end

V
Valery Sizov 已提交
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
    describe :execute do
      context 'runner follow tag list' do
        it "picks build with the same tag" do
          pending_build.tag_list = ["linux"]
          pending_build.save
          specific_runner.tag_list = ["linux"]
          expect(service.execute(specific_runner)).to eq(pending_build)
        end

        it "does not pick build with different tag" do
          pending_build.tag_list = ["linux"]
          pending_build.save
          specific_runner.tag_list = ["win32"]
          expect(service.execute(specific_runner)).to be_falsey
        end

        it "picks build without tag" do
          expect(service.execute(specific_runner)).to eq(pending_build)
        end

        it "does not pick build with tag" do
          pending_build.tag_list = ["linux"]
          pending_build.save
          expect(service.execute(specific_runner)).to be_falsey
        end

        it "pick build without tag" do
          specific_runner.tag_list = ["win32"]
          expect(service.execute(specific_runner)).to eq(pending_build)
        end
D
Douwe Maan 已提交
46 47
      end

V
Valery Sizov 已提交
48 49
      context 'allow shared runners' do
        before do
50
          gl_project.gitlab_ci_project.update(shared_runners_enabled: true)
V
Valery Sizov 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        end

        context 'shared runner' do
          let(:build) { service.execute(shared_runner) }

          it { expect(build).to be_kind_of(Build) }
          it { expect(build).to be_valid }
          it { expect(build).to be_running }
          it { expect(build.runner).to eq(shared_runner) }
        end

        context 'specific runner' do
          let(:build) { service.execute(specific_runner) }

          it { expect(build).to be_kind_of(Build) }
          it { expect(build).to be_valid }
          it { expect(build).to be_running }
          it { expect(build.runner).to eq(specific_runner) }
        end
D
Douwe Maan 已提交
70 71
      end

V
Valery Sizov 已提交
72
      context 'disallow shared runners' do
K
Kamil Trzcinski 已提交
73 74 75 76
        before do
          gl_project.gitlab_ci_project.update(shared_runners_enabled: false)
        end

V
Valery Sizov 已提交
77 78
        context 'shared runner' do
          let(:build) { service.execute(shared_runner) }
D
Douwe Maan 已提交
79

V
Valery Sizov 已提交
80 81
          it { expect(build).to be_nil }
        end
D
Douwe Maan 已提交
82

V
Valery Sizov 已提交
83 84
        context 'specific runner' do
          let(:build) { service.execute(specific_runner) }
D
Douwe Maan 已提交
85

V
Valery Sizov 已提交
86 87 88 89 90
          it { expect(build).to be_kind_of(Build) }
          it { expect(build).to be_valid }
          it { expect(build).to be_running }
          it { expect(build.runner).to eq(specific_runner) }
        end
D
Douwe Maan 已提交
91 92 93 94
      end
    end
  end
end