diff options
Diffstat (limited to 'spec/services')
12 files changed, 130 insertions, 26 deletions
diff --git a/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb b/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb index 7fd32288893..b3b8e34dd8e 100644 --- a/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb +++ b/spec/services/ci/create_pipeline_service/cross_project_pipeline_spec.rb @@ -53,8 +53,6 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do end context 'when sidekiq processes the job', :sidekiq_inline do - let_it_be(:runner) { create(:ci_runner, :online) } - it 'transitions to pending status and triggers a downstream pipeline' do pipeline = create_pipeline! diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 052727401dd..3316f8c3d9b 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -7,7 +7,6 @@ RSpec.describe Ci::CreatePipelineService do let_it_be(:project, reload: true) { create(:project, :repository) } let_it_be(:user, reload: true) { project.owner } - let_it_be(:runner) { create(:ci_runner, :online, tag_list: %w[postgres mysql ruby]) } let(:ref_name) { 'refs/heads/master' } diff --git a/spec/services/ci/pipeline_processing/shared_processing_service.rb b/spec/services/ci/pipeline_processing/shared_processing_service.rb index 34d9b60217f..13c924a3089 100644 --- a/spec/services/ci/pipeline_processing/shared_processing_service.rb +++ b/spec/services/ci/pipeline_processing/shared_processing_service.rb @@ -859,8 +859,6 @@ RSpec.shared_examples 'Pipeline Processing Service' do end context 'when a bridge job has parallel:matrix config', :sidekiq_inline do - let_it_be(:runner) { create(:ci_runner, :online) } - let(:parent_config) do <<-EOY test: diff --git a/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb b/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb index 9c8e6fd3292..572808cd2db 100644 --- a/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb +++ b/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb @@ -3,7 +3,6 @@ RSpec.shared_context 'Pipeline Processing Service Tests With Yaml' do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { project.owner } - let_it_be(:runner) { create(:ci_runner, :online) } where(:test_file_path) do Dir.glob(Rails.root.join('spec/services/ci/pipeline_processing/test_cases/*.yml')) diff --git a/spec/services/environments/canary_ingress/update_service_spec.rb b/spec/services/environments/canary_ingress/update_service_spec.rb index 0e72fff1ed2..531f7d68a9f 100644 --- a/spec/services/environments/canary_ingress/update_service_spec.rb +++ b/spec/services/environments/canary_ingress/update_service_spec.rb @@ -32,16 +32,6 @@ RSpec.describe Environments::CanaryIngress::UpdateService, :clean_gitlab_redis_c let(:params) { { weight: 50 } } let(:canary_ingress) { ::Gitlab::Kubernetes::Ingress.new(kube_ingress(track: :canary)) } - context 'when canary_ingress_weight_control feature flag is disabled' do - before do - stub_feature_flags(canary_ingress_weight_control: false) - end - - it_behaves_like 'failed request' do - let(:message) { "Feature flag is not enabled on the environment's project." } - end - end - context 'when the actor does not have permission to update environment' do let(:user) { reporter } diff --git a/spec/services/packages/helm/extract_file_metadata_service_spec.rb b/spec/services/packages/helm/extract_file_metadata_service_spec.rb index ea196190e24..273f679b736 100644 --- a/spec/services/packages/helm/extract_file_metadata_service_spec.rb +++ b/spec/services/packages/helm/extract_file_metadata_service_spec.rb @@ -38,9 +38,7 @@ RSpec.describe Packages::Helm::ExtractFileMetadataService do context 'with Chart.yaml at root' do before do expect_next_instances_of(Gem::Package::TarReader::Entry, 14) do |entry| - expect(entry).to receive(:full_name).exactly(:once) do - 'Chart.yaml' - end + expect(entry).to receive(:full_name).exactly(:once).and_return('Chart.yaml') end end diff --git a/spec/services/packages/helm/process_file_service_spec.rb b/spec/services/packages/helm/process_file_service_spec.rb new file mode 100644 index 00000000000..2e98590a4f4 --- /dev/null +++ b/spec/services/packages/helm/process_file_service_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Helm::ProcessFileService do + let(:package) { create(:helm_package, without_package_files: true, status: 'processing')} + let!(:package_file) { create(:helm_package_file, without_loaded_metadatum: true, package: package) } + let(:channel) { 'stable' } + let(:service) { described_class.new(channel, package_file) } + + let(:expected) do + { + 'apiVersion' => 'v2', + 'description' => 'File, Block, and Object Storage Services for your Cloud-Native Environment', + 'icon' => 'https://rook.io/images/rook-logo.svg', + 'name' => 'rook-ceph', + 'sources' => ['https://github.com/rook/rook'], + 'version' => 'v1.5.8' + } + end + + describe '#execute' do + subject(:execute) { service.execute } + + context 'without a file' do + let(:package_file) { nil } + + it 'returns error', :aggregate_failures do + expect { execute } + .to not_change { Packages::Package.count } + .and not_change { Packages::PackageFile.count } + .and not_change { Packages::Helm::FileMetadatum.count } + .and raise_error(Packages::Helm::ProcessFileService::ExtractionError, 'Helm chart was not processed - package_file is not set') + end + end + + context 'with existing package' do + let!(:existing_package) { create(:helm_package, project: package.project, name: 'rook-ceph', version: 'v1.5.8') } + + it 'reuses existing package', :aggregate_failures do + expect { execute } + .to change { Packages::Package.count }.from(2).to(1) + .and not_change { package.name } + .and not_change { package.version } + .and not_change { package.status } + .and not_change { Packages::PackageFile.count } + .and change { package_file.file_name }.from(package_file.file_name).to("#{expected['name']}-#{expected['version']}.tgz") + .and change { Packages::Helm::FileMetadatum.count }.from(1).to(2) + .and change { package_file.helm_file_metadatum }.from(nil) + + expect { package.reload } + .to raise_error(ActiveRecord::RecordNotFound) + + expect(package_file.helm_file_metadatum.channel).to eq(channel) + expect(package_file.helm_file_metadatum.metadata).to eq(expected) + end + end + + context 'with a valid file' do + it 'processes file', :aggregate_failures do + expect { execute } + .to not_change { Packages::Package.count } + .and change { package.name }.from(package.name).to(expected['name']) + .and change { package.version }.from(package.version).to(expected['version']) + .and change { package.status }.from('processing').to('default') + .and not_change { Packages::PackageFile.count } + .and change { package_file.file_name }.from(package_file.file_name).to("#{expected['name']}-#{expected['version']}.tgz") + .and change { Packages::Helm::FileMetadatum.count }.by(1) + .and change { package_file.helm_file_metadatum }.from(nil) + + expect(package_file.helm_file_metadatum.channel).to eq(channel) + expect(package_file.helm_file_metadatum.metadata).to eq(expected) + end + end + + context 'without Chart.yaml' do + before do + expect_next_instances_of(Gem::Package::TarReader::Entry, 14) do |entry| + expect(entry).to receive(:full_name).exactly(:once).and_wrap_original do |m, *args| + m.call(*args) + '_suffix' + end + end + end + + it { expect { execute }.to raise_error(Packages::Helm::ExtractFileMetadataService::ExtractionError, 'Chart.yaml not found within a directory') } + end + + context 'with Chart.yaml at root' do + before do + expect_next_instances_of(Gem::Package::TarReader::Entry, 14) do |entry| + expect(entry).to receive(:full_name).exactly(:once).and_return('Chart.yaml') + end + end + + it { expect { execute }.to raise_error(Packages::Helm::ExtractFileMetadataService::ExtractionError, 'Chart.yaml not found within a directory') } + end + + context 'with an invalid YAML' do + before do + expect_next_instance_of(Gem::Package::TarReader::Entry) do |entry| + expect(entry).to receive(:read).and_return('{') + end + end + + it { expect { execute }.to raise_error(Packages::Helm::ExtractFileMetadataService::ExtractionError, 'Error while parsing Chart.yaml: (<unknown>): did not find expected node content while parsing a flow node at line 2 column 1') } + end + end +end diff --git a/spec/services/projects/update_remote_mirror_service_spec.rb b/spec/services/projects/update_remote_mirror_service_spec.rb index 96dbfe8e0b7..feb70ddaa46 100644 --- a/spec/services/projects/update_remote_mirror_service_spec.rb +++ b/spec/services/projects/update_remote_mirror_service_spec.rb @@ -13,21 +13,36 @@ RSpec.describe Projects::UpdateRemoteMirrorService do describe '#execute' do let(:retries) { 0 } + let(:inmemory) { true } subject(:execute!) { service.execute(remote_mirror, retries) } before do + stub_feature_flags(update_remote_mirror_inmemory: inmemory) project.repository.add_branch(project.owner, 'existing-branch', 'master') allow(remote_mirror) .to receive(:update_repository) + .with(inmemory_remote: inmemory) .and_return(double(divergent_refs: [])) end - it 'ensures the remote exists' do - expect(remote_mirror).to receive(:ensure_remote!) + context 'with in-memory remote disabled' do + let(:inmemory) { false } - execute! + it 'ensures the remote exists' do + expect(remote_mirror).to receive(:ensure_remote!) + + execute! + end + end + + context 'with in-memory remote enabled' do + it 'does not ensure the remote exists' do + expect(remote_mirror).not_to receive(:ensure_remote!) + + execute! + end end it 'does not fetch the remote repository' do diff --git a/spec/services/protected_branches/create_service_spec.rb b/spec/services/protected_branches/create_service_spec.rb index 986322e4d87..45462831a31 100644 --- a/spec/services/protected_branches/create_service_spec.rb +++ b/spec/services/protected_branches/create_service_spec.rb @@ -40,7 +40,7 @@ RSpec.describe ProtectedBranches::CreateService do context 'when a policy restricts rule creation' do before do - policy = instance_double(ProtectedBranchPolicy, can?: false) + policy = instance_double(ProtectedBranchPolicy, allowed?: false) expect(ProtectedBranchPolicy).to receive(:new).and_return(policy) end diff --git a/spec/services/protected_branches/destroy_service_spec.rb b/spec/services/protected_branches/destroy_service_spec.rb index 98d31147754..47a048e7033 100644 --- a/spec/services/protected_branches/destroy_service_spec.rb +++ b/spec/services/protected_branches/destroy_service_spec.rb @@ -18,7 +18,7 @@ RSpec.describe ProtectedBranches::DestroyService do context 'when a policy restricts rule deletion' do before do - policy = instance_double(ProtectedBranchPolicy, can?: false) + policy = instance_double(ProtectedBranchPolicy, allowed?: false) expect(ProtectedBranchPolicy).to receive(:new).and_return(policy) end diff --git a/spec/services/protected_branches/update_service_spec.rb b/spec/services/protected_branches/update_service_spec.rb index fdfbdf2e6ae..88e58ad5907 100644 --- a/spec/services/protected_branches/update_service_spec.rb +++ b/spec/services/protected_branches/update_service_spec.rb @@ -27,7 +27,7 @@ RSpec.describe ProtectedBranches::UpdateService do context 'when a policy restricts rule creation' do before do - policy = instance_double(ProtectedBranchPolicy, can?: false) + policy = instance_double(ProtectedBranchPolicy, allowed?: false) expect(ProtectedBranchPolicy).to receive(:new).and_return(policy) end diff --git a/spec/services/repositories/changelog_service_spec.rb b/spec/services/repositories/changelog_service_spec.rb index 02d60f076ca..9a5b0f33fbb 100644 --- a/spec/services/repositories/changelog_service_spec.rb +++ b/spec/services/repositories/changelog_service_spec.rb @@ -76,7 +76,7 @@ RSpec.describe Repositories::ChangelogService do recorder = ActiveRecord::QueryRecorder.new { service.execute } changelog = project.repository.blob_at('master', 'CHANGELOG.md')&.data - expect(recorder.count).to eq(11) + expect(recorder.count).to eq(12) expect(changelog).to include('Title 1', 'Title 2') end |