BigW Consortium Gitlab

runners_spec.rb 3.51 KB
Newer Older
1 2
require 'spec_helper'

3
describe Ci::API::Runners do
4 5 6
  include ApiHelpers
  include StubGitlabCalls

7 8
  let(:registration_token) { 'abcdefg123456' }

Valery Sizov committed
9
  before do
10
    stub_gitlab_calls
11
    stub_application_setting(runners_registration_token: registration_token)
Valery Sizov committed
12
  end
13 14

  describe "POST /runners/register" do
15
    context 'when runner token is provided' do
16
      before { post ci_api("/runners/register"), token: registration_token }
17

18
      it 'creates runner with default values' do
19
        expect(response).to have_http_status 201
20
        expect(Ci::Runner.first.run_untagged).to be true
21
      end
22 23
    end

24
    context 'when runner description is provided' do
25 26 27 28
      before do
        post ci_api("/runners/register"), token: registration_token,
                                          description: "server.hostname"
      end
29

30
      it 'creates runner' do
31
        expect(response).to have_http_status 201
32 33
        expect(Ci::Runner.first.description).to eq("server.hostname")
      end
34 35
    end

36
    context 'when runner tags are provided' do
37 38 39 40
      before do
        post ci_api("/runners/register"), token: registration_token,
                                          tag_list: "tag1, tag2"
      end
41

42
      it 'creates runner' do
43
        expect(response).to have_http_status 201
44 45
        expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"])
      end
46 47
    end

48 49 50 51 52 53 54
    context 'when option for running untagged jobs is provided' do
      context 'when tags are provided' do
        it 'creates runner' do
          post ci_api("/runners/register"), token: registration_token,
                                            run_untagged: false,
                                            tag_list: ['tag']

55
          expect(response).to have_http_status 201
56 57 58 59 60 61 62 63 64
          expect(Ci::Runner.first.run_untagged).to be false
        end
      end

      context 'when tags are not provided' do
        it 'does not create runner' do
          post ci_api("/runners/register"), token: registration_token,
                                            run_untagged: false

65
          expect(response).to have_http_status 404
66 67 68 69
        end
      end
    end

70
    context 'when project token is provided' do
71
      let(:project) { FactoryGirl.create(:empty_project) }
72
      before { post ci_api("/runners/register"), token: project.runners_token }
73

74
      it 'creates runner' do
75
        expect(response).to have_http_status 201
76 77
        expect(project.runners.size).to eq(1)
      end
78 79
    end

80 81 82
    context 'when token is invalid' do
      it 'returns 403 error' do
        post ci_api("/runners/register"), token: 'invalid'
83

84
        expect(response).to have_http_status 403
85
      end
86 87
    end

88 89 90
    context 'when no token provided' do
      it 'returns 400 error' do
        post ci_api("/runners/register")
91

92
        expect(response).to have_http_status 400
93
      end
94
    end
95 96 97 98 99 100 101 102 103

    %w(name version revision platform architecture).each do |param|
      context "creates runner with #{param} saved" do
        let(:value) { "#{param}_value" }

        subject { Ci::Runner.first.read_attribute(param.to_sym) }

        it do
          post ci_api("/runners/register"), token: registration_token, info: { param => value }
104
          expect(response).to have_http_status 201
105 106 107 108
          is_expected.to eq(value)
        end
      end
    end
109 110 111
  end

  describe "DELETE /runners/delete" do
Valery Sizov committed
112 113 114
    it 'returns 200' do
      runner = FactoryGirl.create(:ci_runner)
      delete ci_api("/runners/delete"), token: runner.token
115

Valery Sizov committed
116 117 118
      expect(response).to have_http_status 200
      expect(Ci::Runner.count).to eq(0)
    end
119 120
  end
end