BigW Consortium Gitlab

runner_spec.rb 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# == Schema Information
#
# Table name: runners
#
#  id           :integer          not null, primary key
#  token        :string(255)
#  created_at   :datetime
#  updated_at   :datetime
#  description  :string(255)
#  contacted_at :datetime
#  active       :boolean          default(TRUE), not null
#  is_shared    :boolean          default(FALSE)
#  name         :string(255)
#  version      :string(255)
#  revision     :string(255)
#  platform     :string(255)
#  architecture :string(255)
#

require 'spec_helper'

22
describe Ci::Runner do
23 24
  describe '#display_name' do
    it 'should return the description if it has a value' do
Valery Sizov committed
25
      runner = FactoryGirl.build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
26 27 28 29
      expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
    end

    it 'should return the token if it does not have a description' do
30
      runner = FactoryGirl.create(:ci_runner)
31 32 33 34
      expect(runner.display_name).to eq runner.description
    end

    it 'should return the token if the description is an empty string' do
Kamil Trzcinski committed
35
      runner = FactoryGirl.build(:ci_runner, description: '', token: 'token')
36 37 38 39 40
      expect(runner.display_name).to eq runner.token
    end
  end

  describe :assign_to do
41 42
    let!(:project) { FactoryGirl.create :ci_project }
    let!(:shared_runner) { FactoryGirl.create(:ci_shared_runner) }
43 44 45

    before { shared_runner.assign_to(project) }

Dmitriy Zaporozhets committed
46 47 48
    it { expect(shared_runner).to be_specific }
    it { expect(shared_runner.projects).to eq([project]) }
    it { expect(shared_runner.only_for?(project)).to be_truthy }
49 50
  end

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  describe :online do
    subject { Ci::Runner.online }

    before do
      @runner1 = FactoryGirl.create(:ci_shared_runner, contacted_at: 1.year.ago)
      @runner2 = FactoryGirl.create(:ci_shared_runner, contacted_at: 1.second.ago)
    end

    it { is_expected.to eq([@runner2])}
  end

  describe :online? do
    let(:runner) { FactoryGirl.create(:ci_shared_runner) }

    subject { runner.online? }

    context 'never contacted' do
      before { runner.contacted_at = nil }

      it { is_expected.to be_falsey }
    end

    context 'contacted long time ago time' do
      before { runner.contacted_at = 1.year.ago }

      it { is_expected.to be_falsey }
    end

    context 'contacted 1s ago' do
      before { runner.contacted_at = 1.second.ago }

      it { is_expected.to be_truthy }
    end
  end

  describe :status do
    let(:runner) { FactoryGirl.create(:ci_shared_runner, contacted_at: 1.second.ago) }

    subject { runner.status }

    context 'never connected' do
      before { runner.contacted_at = nil }

      it { is_expected.to eq(:not_connected) }
    end

    context 'contacted 1s ago' do
      before { runner.contacted_at = 1.second.ago }

      it { is_expected.to eq(:online) }
    end

    context 'contacted long time ago' do
      before { runner.contacted_at = 1.year.ago }

      it { is_expected.to eq(:offline) }
    end

    context 'inactive' do
      before { runner.active = false }

      it { is_expected.to eq(:paused) }
    end
  end

116 117
  describe "belongs_to_one_project?" do
    it "returns false if there are two projects runner assigned to" do
118 119 120
      runner = FactoryGirl.create(:ci_specific_runner)
      project = FactoryGirl.create(:ci_project)
      project1 = FactoryGirl.create(:ci_project)
121 122 123
      project.runners << runner
      project1.runners << runner

Dmitriy Zaporozhets committed
124
      expect(runner.belongs_to_one_project?).to be_falsey
125 126 127
    end

    it "returns true" do
128 129
      runner = FactoryGirl.create(:ci_specific_runner)
      project = FactoryGirl.create(:ci_project)
130 131
      project.runners << runner

Dmitriy Zaporozhets committed
132
      expect(runner.belongs_to_one_project?).to be_truthy
133 134 135
    end
  end
end