Commit 68a92295 authored by Alessio Caiazza's avatar Alessio Caiazza

Fix cluster_applications_helm factory with a configured cluster

parent d6134709
FactoryGirl.define do FactoryGirl.define do
factory :cluster_applications_helm, class: Clusters::Applications::Helm do factory :cluster_applications_helm, class: Clusters::Applications::Helm do
cluster factory: :cluster cluster factory: %i(cluster provided_by_gcp)
trait :installable do trait :installable do
cluster
status 0 status 0
end end
trait :scheduled do trait :scheduled do
cluster
status 1 status 1
end end
trait :installing do trait :installing do
cluster
status 2 status 2
end end
trait :installed do trait :installed do
cluster
status 3 status 3
end end
trait :errored do trait :errored do
cluster
status(-1) status(-1)
status_reason 'something went wrong' status_reason 'something went wrong'
end end
......
...@@ -4,14 +4,20 @@ describe Clusters::Applications::InstallService do ...@@ -4,14 +4,20 @@ describe Clusters::Applications::InstallService do
describe '#execute' do describe '#execute' do
let(:application) { create(:cluster_applications_helm, :scheduled) } let(:application) { create(:cluster_applications_helm, :scheduled) }
let(:service) { described_class.new(application) } let(:service) { described_class.new(application) }
let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm) }
before do
allow(service).to receive(:helm_api).and_return(helm_client)
end
context 'when there are no errors' do context 'when there are no errors' do
before do before do
expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application) expect(helm_client).to receive(:install).with(application)
allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil) allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil)
end end
it 'make the application installing' do it 'make the application installing' do
expect(application.cluster).not_to be_nil
service.execute service.execute
expect(application).to be_installing expect(application).to be_installing
...@@ -27,7 +33,7 @@ describe Clusters::Applications::InstallService do ...@@ -27,7 +33,7 @@ describe Clusters::Applications::InstallService do
context 'when k8s cluster communication fails' do context 'when k8s cluster communication fails' do
before do before do
error = KubeException.new(500, 'system failure', nil) error = KubeException.new(500, 'system failure', nil)
expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application).and_raise(error) expect(helm_client).to receive(:install).with(application).and_raise(error)
end end
it 'make the application errored' do it 'make the application errored' do
...@@ -43,7 +49,7 @@ describe Clusters::Applications::InstallService do ...@@ -43,7 +49,7 @@ describe Clusters::Applications::InstallService do
it 'make the application errored' do it 'make the application errored' do
expect(application).to receive(:make_installing!).once.and_raise(ActiveRecord::RecordInvalid) expect(application).to receive(:make_installing!).once.and_raise(ActiveRecord::RecordInvalid)
expect_any_instance_of(Gitlab::Kubernetes::Helm).not_to receive(:install) expect(helm_client).not_to receive(:install)
service.execute service.execute
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment