debian-mirror-gitlab/spec/services/clusters/applications/install_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.5 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Clusters::Applications::InstallService do
2018-03-17 18:26:18 +05:30
describe '#execute' do
let(:application) { create(:clusters_applications_helm, :scheduled) }
let!(:install_command) { application.install_command }
let(:service) { described_class.new(application) }
2020-04-08 14:13:33 +05:30
let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm::API) }
2018-03-17 18:26:18 +05:30
before do
allow(service).to receive(:install_command).and_return(install_command)
allow(service).to receive(:helm_api).and_return(helm_client)
end
context 'when there are no errors' do
before do
expect(helm_client).to receive(:install).with(install_command)
allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil)
end
it 'make the application installing' do
expect(application.cluster).not_to be_nil
service.execute
expect(application).to be_installing
end
it 'schedule async installation status check' do
expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once
service.execute
end
end
context 'when k8s cluster communication fails' do
2019-02-15 15:39:39 +05:30
let(:error) { Kubeclient::HttpError.new(500, 'system failure', nil) }
2018-03-17 18:26:18 +05:30
before do
expect(helm_client).to receive(:install).with(install_command).and_raise(error)
end
2019-07-07 11:18:12 +05:30
include_examples 'logs kubernetes errors' do
let(:error_name) { 'Kubeclient::HttpError' }
let(:error_message) { 'system failure' }
let(:error_code) { 500 }
end
2018-03-17 18:26:18 +05:30
it 'make the application errored' do
service.execute
expect(application).to be_errored
2019-02-15 15:39:39 +05:30
expect(application.status_reason).to match('Kubernetes error: 500')
end
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
context 'a non kubernetes error happens' do
2018-11-18 11:00:15 +05:30
let(:application) { create(:clusters_applications_helm, :scheduled) }
2019-07-07 11:18:12 +05:30
let(:error) { StandardError.new('something bad happened') }
2019-02-15 15:39:39 +05:30
before do
2019-07-31 22:56:46 +05:30
expect(helm_client).to receive(:install).with(install_command).and_raise(error)
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
include_examples 'logs kubernetes errors' do
let(:error_name) { 'StandardError' }
let(:error_message) { 'something bad happened' }
let(:error_code) { nil }
end
2018-03-17 18:26:18 +05:30
it 'make the application errored' do
service.execute
expect(application).to be_errored
2019-07-31 22:56:46 +05:30
expect(application.status_reason).to eq('Failed to install.')
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
end