summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/seed/runner_fleet_rake_spec.rb
blob: e0390d2aa098e8b7f96d2c8110a788b4cbab11cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# frozen_string_literal: true

require 'rake_helper'

RSpec.describe 'gitlab:seed:runner_fleet rake task', :silence_stdout, feature_category: :runner_fleet do
  let(:registration_prefix) { 'rf-' }
  let(:runner_count) { 10 }
  let(:job_count) { 20 }
  let(:task_params) { [username, registration_prefix, runner_count, job_count] }
  let(:runner_releases_url) do
    ::Gitlab::CurrentSettings.current_application_settings.public_runner_releases_url
  end

  before do
    Rake.application.rake_require('tasks/gitlab/seed/runner_fleet')

    WebMock.stub_request(:get, runner_releases_url).to_return(
      body: '[]',
      status: 200,
      headers: { 'Content-Type' => 'application/json' }
    )
  end

  subject(:rake_task) { run_rake_task('gitlab:seed:runner_fleet', task_params) }

  context 'with admin username', :enable_admin_mode do
    let(:username) { 'runner_fleet_seed' }
    let!(:admin) { create(:user, :admin, username: username) }

    it 'performs runner fleet seed successfully' do
      expect { rake_task }
        .to change { Group.count }.by(6)
        .and change { Project.count }.by(3)
        .and change { Ci::Runner.count }.by(runner_count)
        .and change { Ci::Runner.instance_type.count }.by(1)
        .and change { Ci::Build.count }.by(job_count)

      expect(Group.search(registration_prefix).count).to eq 6
      expect(Project.search(registration_prefix).count).to eq 3
      expect(Ci::Runner.search(registration_prefix).count).to eq runner_count
    end
  end
end