From 68a9229502de26c191dbd56738828736876217f6 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Tue, 7 Nov 2017 11:50:00 +0100 Subject: Fix cluster_applications_helm factory with a configured cluster --- spec/factories/clusters/applications/helm.rb | 7 +------ spec/services/clusters/applications/install_service_spec.rb | 12 +++++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index b63e26125d1..23818f19edf 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -1,29 +1,24 @@ FactoryGirl.define do factory :cluster_applications_helm, class: Clusters::Applications::Helm do - cluster factory: :cluster + cluster factory: %i(cluster provided_by_gcp) trait :installable do - cluster status 0 end trait :scheduled do - cluster status 1 end trait :installing do - cluster status 2 end trait :installed do - cluster status 3 end trait :errored do - cluster status(-1) status_reason 'something went wrong' end diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb index ae8dc7b2bd9..408f7e4354e 100644 --- a/spec/services/clusters/applications/install_service_spec.rb +++ b/spec/services/clusters/applications/install_service_spec.rb @@ -4,14 +4,20 @@ describe Clusters::Applications::InstallService do describe '#execute' do let(:application) { create(:cluster_applications_helm, :scheduled) } 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 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) end it 'make the application installing' do + expect(application.cluster).not_to be_nil service.execute expect(application).to be_installing @@ -27,7 +33,7 @@ describe Clusters::Applications::InstallService do context 'when k8s cluster communication fails' do before do 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 it 'make the application errored' do @@ -43,7 +49,7 @@ describe Clusters::Applications::InstallService do it 'make the application errored' do 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 -- cgit v1.2.1