diff options
Diffstat (limited to 'spec/services/clusters')
4 files changed, 60 insertions, 57 deletions
diff --git a/spec/services/clusters/aws/authorize_role_service_spec.rb b/spec/services/clusters/aws/authorize_role_service_spec.rb index 530268340b7..3d12400a47b 100644 --- a/spec/services/clusters/aws/authorize_role_service_spec.rb +++ b/spec/services/clusters/aws/authorize_role_service_spec.rb @@ -53,6 +53,12 @@ RSpec.describe Clusters::Aws::AuthorizeRoleService do expect(subject.status).to eq(:unprocessable_entity) expect(subject.body).to eq({}) end + + it 'logs the error' do + expect(::Gitlab::ErrorTracking).to receive(:track_exception) + + subject + end end context 'cannot create role' do diff --git a/spec/services/clusters/cleanup/project_namespace_service_spec.rb b/spec/services/clusters/cleanup/project_namespace_service_spec.rb index 761ad8dd8c8..605aaea17e4 100644 --- a/spec/services/clusters/cleanup/project_namespace_service_spec.rb +++ b/spec/services/clusters/cleanup/project_namespace_service_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Clusters::Cleanup::ProjectNamespaceService do execution_count: 0 } end + let(:kubeclient_instance_double) do instance_double(Gitlab::Kubernetes::KubeClient, delete_namespace: nil, delete_service_account: nil) end diff --git a/spec/services/clusters/cleanup/service_account_service_spec.rb b/spec/services/clusters/cleanup/service_account_service_spec.rb index 6fe3d0c286e..f256df1b2fc 100644 --- a/spec/services/clusters/cleanup/service_account_service_spec.rb +++ b/spec/services/clusters/cleanup/service_account_service_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Clusters::Cleanup::ServiceAccountService do execution_count: 0 } end + let(:kubeclient_instance_double) do instance_double(Gitlab::Kubernetes::KubeClient, delete_namespace: nil, delete_service_account: nil) end diff --git a/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb b/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb index 3b155d95345..1f6ad218927 100644 --- a/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb +++ b/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb @@ -36,94 +36,89 @@ RSpec.describe Clusters::ParseClusterApplicationsArtifactService do let(:job) { deployment.deployable } let(:artifact) { create(:ci_job_artifact, :cluster_applications, job: job) } - context 'when cluster_applications_artifact feature flag is disabled' do - before do - stub_feature_flags(cluster_applications_artifact: false) - end - - it 'does not call Gitlab::Kubernetes::Helm::Parsers::ListV2 and returns success immediately' do - expect(Gitlab::Kubernetes::Helm::Parsers::ListV2).not_to receive(:new) + it 'calls Gitlab::Kubernetes::Helm::Parsers::ListV2' do + expect(Gitlab::Kubernetes::Helm::Parsers::ListV2).to receive(:new).and_call_original - result = described_class.new(job, user).execute(artifact) + result = described_class.new(job, user).execute(artifact) - expect(result[:status]).to eq(:success) - end + expect(result[:status]).to eq(:success) end - context 'when cluster_applications_artifact feature flag is enabled for project' do - before do - stub_feature_flags(cluster_applications_artifact: job.project) + context 'artifact is not of cluster_applications type' do + let(:artifact) { create(:ci_job_artifact, :archive) } + let(:job) { artifact.job } + + it 'raise ArgumentError' do + expect do + described_class.new(job, user).execute(artifact) + end.to raise_error(ArgumentError, 'Artifact is not cluster_applications file type') end + end - it 'calls Gitlab::Kubernetes::Helm::Parsers::ListV2' do - expect(Gitlab::Kubernetes::Helm::Parsers::ListV2).to receive(:new).and_call_original + context 'artifact exceeds acceptable size' do + it 'returns an error' do + stub_const("#{described_class}::MAX_ACCEPTABLE_ARTIFACT_SIZE", 1.byte) result = described_class.new(job, user).execute(artifact) - expect(result[:status]).to eq(:success) + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq('Cluster_applications artifact too big. Maximum allowable size: 1 Byte') end + end - context 'artifact is not of cluster_applications type' do - let(:artifact) { create(:ci_job_artifact, :archive) } - let(:job) { artifact.job } + context 'job has no deployment' do + let(:job) { build(:ci_build) } - it 'raise ArgumentError' do - expect do - described_class.new(job, user).execute(artifact) - end.to raise_error(ArgumentError, 'Artifact is not cluster_applications file type') - end + it 'returns an error' do + result = described_class.new(job, user).execute(artifact) + + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq('No deployment found for this job') end + end - context 'artifact exceeds acceptable size' do - it 'returns an error' do - stub_const("#{described_class}::MAX_ACCEPTABLE_ARTIFACT_SIZE", 1.byte) + context 'job has no deployment cluster' do + let(:deployment) { create(:deployment) } + let(:job) { deployment.deployable } - result = described_class.new(job, user).execute(artifact) + it 'returns an error' do + result = described_class.new(job, user).execute(artifact) - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('Cluster_applications artifact too big. Maximum allowable size: 1 Byte') - end + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq('No deployment cluster found for this job') end + end - context 'job has no deployment' do - let(:job) { build(:ci_build) } + context 'blob is empty' do + let(:file) { fixture_file_upload(Rails.root.join("spec/fixtures/helm/helm_list_v2_empty_blob.json.gz")) } + let(:artifact) { create(:ci_job_artifact, :cluster_applications, job: job, file: file) } - it 'returns an error' do - result = described_class.new(job, user).execute(artifact) + it 'returns success' do + result = described_class.new(job, user).execute(artifact) - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('No deployment found for this job') - end + expect(result[:status]).to eq(:success) end + end - context 'job has no deployment cluster' do - let(:deployment) { create(:deployment) } - let(:job) { deployment.deployable } + context 'job has deployment cluster' do + context 'current user does not have access to deployment cluster' do + let(:other_user) { create(:user) } it 'returns an error' do - result = described_class.new(job, user).execute(artifact) + result = described_class.new(job, other_user).execute(artifact) expect(result[:status]).to eq(:error) expect(result[:message]).to eq('No deployment cluster found for this job') end end - context 'job has deployment cluster' do - context 'current user does not have access to deployment cluster' do - let(:other_user) { create(:user) } - - it 'returns an error' do - result = described_class.new(job, other_user).execute(artifact) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('No deployment cluster found for this job') - end - end + it 'does not affect unpermitted cluster applications' do + expect(Clusters::ParseClusterApplicationsArtifactService::RELEASE_NAMES).to contain_exactly('cilium') + end - Clusters::ParseClusterApplicationsArtifactService::RELEASE_NAMES.each do |release_name| - context release_name do - include_examples 'parse cluster applications artifact', release_name - end + Clusters::ParseClusterApplicationsArtifactService::RELEASE_NAMES.each do |release_name| + context release_name do + include_examples 'parse cluster applications artifact', release_name end end end |