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

127 lines
3.9 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe Clusters::Applications::InstallService do
describe '#execute' do
let(:application) { create(:clusters_applications_helm, :scheduled) }
let!(:install_command) { application.install_command }
let(:service) { described_class.new(application) }
let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm::Api) }
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
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
2019-05-30 16:15:17 +05:30
it 'logs errors' do
expect(service.send(:logger)).to receive(:error).with(
{
exception: 'Kubeclient::HttpError',
message: 'system failure',
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.project_ids,
group_ids: [],
error_code: 500
}
)
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error,
extra: {
exception: 'Kubeclient::HttpError',
message: 'system failure',
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.project_ids,
group_ids: [],
error_code: 500
}
)
service.execute
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-05-30 16:15:17 +05:30
let(:error) { StandardError.new("something bad happened") }
2019-02-15 15:39:39 +05:30
before do
expect(application).to receive(:make_installing!).once.and_raise(error)
end
2018-03-17 18:26:18 +05:30
it 'make the application errored' do
expect(helm_client).not_to receive(:install)
service.execute
expect(application).to be_errored
2019-02-15 15:39:39 +05:30
expect(application.status_reason).to eq("Can't start installation process.")
end
2019-05-30 16:15:17 +05:30
it 'logs errors' do
expect(service.send(:logger)).to receive(:error).with(
{
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
group_ids: []
}
)
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error,
extra: {
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
group_ids: []
}
)
service.execute
end
2018-03-17 18:26:18 +05:30
end
end
end