diff options
Diffstat (limited to 'spec/models/clusters/applications/runner_spec.rb')
-rw-r--r-- | spec/models/clusters/applications/runner_spec.rb | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index 6972fc03415..4f0cd0efe9c 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Runner do @@ -11,6 +13,14 @@ describe Clusters::Applications::Runner do it { is_expected.to belong_to(:runner) } + describe '#can_uninstall?' do + let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) } + + subject { gitlab_runner.can_uninstall? } + + it { is_expected.to be_falsey } + end + describe '#install_command' do let(:kubeclient) { double('kubernetes client') } let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) } @@ -19,10 +29,10 @@ describe Clusters::Applications::Runner do it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) } - it 'should be initialized with 4 arguments' do + it 'is initialized with 4 arguments' do expect(subject.name).to eq('runner') expect(subject.chart).to eq('runner/gitlab-runner') - expect(subject.version).to eq('0.2.0') + expect(subject.version).to eq(Clusters::Applications::Runner::VERSION) expect(subject).to be_rbac expect(subject.repository).to eq('https://charts.gitlab.io') expect(subject.files).to eq(gitlab_runner.files) @@ -39,8 +49,8 @@ describe Clusters::Applications::Runner do context 'application failed to install previously' do let(:gitlab_runner) { create(:clusters_applications_runner, :errored, runner: ci_runner, version: '0.1.13') } - it 'should be initialized with the locked version' do - expect(subject.version).to eq('0.2.0') + it 'is initialized with the locked version' do + expect(subject.version).to eq(Clusters::Applications::Runner::VERSION) end end end @@ -51,7 +61,7 @@ describe Clusters::Applications::Runner do subject { application.files } - it 'should include runner valid values' do + it 'includes runner valid values' do expect(values).to include('concurrent') expect(values).to include('checkInterval') expect(values).to include('rbac') @@ -59,29 +69,62 @@ describe Clusters::Applications::Runner do expect(values).to include('privileged: true') expect(values).to include('image: ubuntu:16.04') expect(values).to include('resources') - expect(values).to match(/runnerToken: '?#{ci_runner.token}/) - expect(values).to match(/gitlabUrl: '?#{Gitlab::Routing.url_helpers.root_url}/) + expect(values).to match(/runnerToken: '?#{Regexp.escape(ci_runner.token)}/) + expect(values).to match(/gitlabUrl: '?#{Regexp.escape(Gitlab::Routing.url_helpers.root_url)}/) end context 'without a runner' do - let(:project) { create(:project) } - let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } let(:application) { create(:clusters_applications_runner, runner: nil, cluster: cluster) } + let(:runner) { application.runner } + + shared_examples 'runner creation' do + it 'creates a runner' do + expect { subject }.to change { Ci::Runner.count }.by(1) + end + + it 'uses the new runner token' do + expect(values).to match(/runnerToken: '?#{Regexp.escape(runner.token)}/) + end + end + + context 'project cluster' do + let(:project) { create(:project) } + let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } - it 'creates a runner' do - expect do + include_examples 'runner creation' + + it 'creates a project runner' do subject - end.to change { Ci::Runner.count }.by(1) + + expect(runner).to be_project_type + expect(runner.projects).to eq [project] + end end - it 'uses the new runner token' do - expect(values).to match(/runnerToken: '?#{application.reload.runner.token}/) + context 'group cluster' do + let(:group) { create(:group) } + let(:cluster) { create(:cluster, :with_installed_helm, cluster_type: :group_type, groups: [group]) } + + include_examples 'runner creation' + + it 'creates a group runner' do + subject + + expect(runner).to be_group_type + expect(runner.groups).to eq [group] + end end - it 'assigns the new runner to runner' do - subject + context 'instance cluster' do + let(:cluster) { create(:cluster, :with_installed_helm, :instance) } + + include_examples 'runner creation' + + it 'creates an instance runner' do + subject - expect(application.reload.runner).to be_project_type + expect(runner).to be_instance_type + end end end @@ -108,7 +151,7 @@ describe Clusters::Applications::Runner do allow(application).to receive(:chart_values).and_return(stub_values) end - it 'should overwrite values.yaml' do + it 'overwrites values.yaml' do expect(values).to match(/privileged: '?#{application.privileged}/) end end |