This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

runners_controller_spec.rb 2.56 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
5
require 'spec_helper'

describe Admin::RunnersController do
6
  let!(:runner) { create(:ci_runner) }
7
8
9
10
11
12

  before do
    sign_in(create(:admin))
  end

  describe '#index' do
13
14
    render_views

15
16
17
    it 'lists all runners' do
      get :index

18
      expect(response).to have_gitlab_http_status(200)
19
    end
20
21
22
23
24
25

    it 'avoids N+1 queries', :request_store do
      get :index

      control_count = ActiveRecord::QueryRecorder.new { get :index }.count

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
26
      create_list(:ci_runner, 5, :tagged_only)
27
28

      # There is still an N+1 query for `runner.builds.count`
Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
29
30
      # We also need to add 1 because it takes 2 queries to preload tags
      expect { get :index }.not_to exceed_query_limit(control_count + 6)
31
32
33
34
35

      expect(response).to have_gitlab_http_status(200)
      expect(response.body).to have_content('tag1')
      expect(response.body).to have_content('tag2')
    end
36
37
38
39
  end

  describe '#show' do
    it 'shows a particular runner' do
blackst0ne's avatar
blackst0ne committed
40
      get :show, params: { id: runner.id }
41

42
      expect(response).to have_gitlab_http_status(200)
43
44
45
    end

    it 'shows 404 for unknown runner' do
blackst0ne's avatar
blackst0ne committed
46
      get :show, params: { id: 0 }
47

48
      expect(response).to have_gitlab_http_status(404)
49
50
51
52
53
54
55
    end
  end

  describe '#update' do
    it 'updates the runner and ticks the queue' do
      new_desc = runner.description.swapcase

Lin Jen-Shin's avatar
Lin Jen-Shin committed
56
      expect do
blackst0ne's avatar
blackst0ne committed
57
        post :update, params: { id: runner.id, runner: { description: new_desc } }
Lin Jen-Shin's avatar
Lin Jen-Shin committed
58
      end.to change { runner.ensure_runner_queue_value }
59
60
61

      runner.reload

62
      expect(response).to have_gitlab_http_status(302)
63
64
65
66
67
68
      expect(runner.description).to eq(new_desc)
    end
  end

  describe '#destroy' do
    it 'destroys the runner' do
blackst0ne's avatar
blackst0ne committed
69
      delete :destroy, params: { id: runner.id }
70

71
      expect(response).to have_gitlab_http_status(302)
72
73
74
75
76
77
78
79
      expect(Ci::Runner.find_by(id: runner.id)).to be_nil
    end
  end

  describe '#resume' do
    it 'marks the runner as active and ticks the queue' do
      runner.update(active: false)

Lin Jen-Shin's avatar
Lin Jen-Shin committed
80
      expect do
blackst0ne's avatar
blackst0ne committed
81
        post :resume, params: { id: runner.id }
Lin Jen-Shin's avatar
Lin Jen-Shin committed
82
      end.to change { runner.ensure_runner_queue_value }
83
84
85

      runner.reload

86
      expect(response).to have_gitlab_http_status(302)
87
88
89
90
91
92
93
94
      expect(runner.active).to eq(true)
    end
  end

  describe '#pause' do
    it 'marks the runner as inactive and ticks the queue' do
      runner.update(active: true)

Lin Jen-Shin's avatar
Lin Jen-Shin committed
95
      expect do
blackst0ne's avatar
blackst0ne committed
96
        post :pause, params: { id: runner.id }
Lin Jen-Shin's avatar
Lin Jen-Shin committed
97
      end.to change { runner.ensure_runner_queue_value }
98
99
100

      runner.reload

101
      expect(response).to have_gitlab_http_status(302)
102
103
104
105
      expect(runner.active).to eq(false)
    end
  end
end