Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-28 15:14:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-28 15:14:07 +0300
commit22ecb1e3fc02bb923c3e9941b1baa849348a036f (patch)
treec01d9e91564f50e790a63c71675dd0f6e7735153 /spec/models
parent5eab6dcdd923ca375b86d6993f20a3e37dbd7a51 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/namespace_spec.rb31
-rw-r--r--spec/models/uploads/fog_spec.rb87
2 files changed, 115 insertions, 3 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 4e3d8f633b7..2d6ddd74dfd 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -465,6 +465,14 @@ RSpec.describe Namespace, feature_category: :subgroups do
end
end
+ context 'when parent is nil' do
+ let(:namespace) { build(:group, parent: nil) }
+
+ it 'returns []' do
+ expect(namespace.traversal_ids).to eq []
+ end
+ end
+
context 'when made a child group' do
let!(:namespace) { create(:group) }
let!(:parent_namespace) { create(:group, children: [namespace]) }
@@ -1961,6 +1969,29 @@ RSpec.describe Namespace, feature_category: :subgroups do
expect(very_deep_nested_group.root_ancestor).to eq(root_group)
end
end
+
+ context 'when parent is changed' do
+ let(:group) { create(:group) }
+ let(:new_parent) { create(:group) }
+
+ shared_examples 'updates root_ancestor' do
+ it do
+ expect { subject }.to change { group.root_ancestor }.from(group).to(new_parent)
+ end
+ end
+
+ context 'by object' do
+ subject { group.parent = new_parent }
+
+ include_examples 'updates root_ancestor'
+ end
+
+ context 'by id' do
+ subject { group.parent_id = new_parent.id }
+
+ include_examples 'updates root_ancestor'
+ end
+ end
end
describe '#full_path_before_last_save' do
diff --git a/spec/models/uploads/fog_spec.rb b/spec/models/uploads/fog_spec.rb
index 1ffe7c6c43b..a1b0bcf95e0 100644
--- a/spec/models/uploads/fog_spec.rb
+++ b/spec/models/uploads/fog_spec.rb
@@ -3,10 +3,21 @@
require 'spec_helper'
RSpec.describe Uploads::Fog do
+ let(:credentials) do
+ {
+ provider: "AWS",
+ aws_access_key_id: "AWS_ACCESS_KEY_ID",
+ aws_secret_access_key: "AWS_SECRET_ACCESS_KEY",
+ region: "eu-central-1"
+ }
+ end
+
+ let(:bucket_prefix) { nil }
let(:data_store) { described_class.new }
+ let(:config) { { connection: credentials, bucket_prefix: bucket_prefix, remote_directory: 'uploads' } }
before do
- stub_uploads_object_storage(FileUploader)
+ stub_uploads_object_storage(FileUploader, config: config)
end
describe '#available?' do
@@ -18,7 +29,7 @@ RSpec.describe Uploads::Fog do
context 'when object storage is disabled' do
before do
- stub_uploads_object_storage(FileUploader, enabled: false)
+ stub_uploads_object_storage(FileUploader, config: config, enabled: false)
end
it { is_expected.to be_falsy }
@@ -28,6 +39,60 @@ RSpec.describe Uploads::Fog do
context 'model with uploads' do
let(:project) { create(:project) }
let(:relation) { project.uploads }
+ let(:connection) { ::Fog::Storage.new(credentials) }
+ let(:paths) { relation.pluck(:path) }
+
+ # Only fog-aws simulates mocking of deleting an object properly.
+ # We'll just test that the various providers implement the require methods.
+ describe 'Fog provider acceptance tests' do
+ let!(:uploads) { create_list(:upload, 2, :with_file, :issuable_upload, model: project) }
+
+ shared_examples 'Fog provider' do
+ describe '#get_object' do
+ it 'returns a Hash with a body' do
+ expect(connection.get_object('uploads', paths.first)[:body]).not_to be_nil
+ end
+ end
+
+ describe '#delete_object' do
+ it 'returns true' do
+ expect(connection.delete_object('uploads', paths.first)).to be_truthy
+ end
+ end
+ end
+
+ before do
+ uploads.each { |upload| upload.retrieve_uploader.migrate!(2) }
+ end
+
+ context 'with AWS provider' do
+ it_behaves_like 'Fog provider'
+ end
+
+ context 'with Google provider' do
+ let(:credentials) do
+ {
+ provider: "Google",
+ google_storage_access_key_id: 'ACCESS_KEY_ID',
+ google_storage_secret_access_key: 'SECRET_ACCESS_KEY'
+ }
+ end
+
+ it_behaves_like 'Fog provider'
+ end
+
+ context 'with AzureRM provider' do
+ let(:credentials) do
+ {
+ provider: 'AzureRM',
+ azure_storage_account_name: 'test-access-id',
+ azure_storage_access_key: 'secret'
+ }
+ end
+
+ it_behaves_like 'Fog provider'
+ end
+ end
describe '#keys' do
let!(:uploads) { create_list(:upload, 2, :object_storage, uploader: FileUploader, model: project) }
@@ -40,7 +105,7 @@ RSpec.describe Uploads::Fog do
end
describe '#delete_keys' do
- let(:connection) { ::Fog::Storage.new(FileUploader.object_store_credentials) }
+ let(:connection) { ::Fog::Storage.new(credentials) }
let(:keys) { data_store.keys(relation) }
let(:paths) { relation.pluck(:path) }
let!(:uploads) { create_list(:upload, 2, :with_file, :issuable_upload, model: project) }
@@ -63,6 +128,22 @@ RSpec.describe Uploads::Fog do
end
end
+ context 'with bucket prefix' do
+ let(:bucket_prefix) { 'test-prefix' }
+
+ it 'deletes multiple data' do
+ paths.each do |path|
+ expect(connection.get_object('uploads', File.join(bucket_prefix, path))[:body]).not_to be_nil
+ end
+
+ subject
+
+ paths.each do |path|
+ expect { connection.get_object('uploads', File.join(bucket_prefix, path))[:body] }.to raise_error(Excon::Error::NotFound)
+ end
+ end
+ end
+
context 'when one of keys is missing' do
let(:keys) { ['unknown'] + super() }