diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 21:08:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 21:08:54 +0300 |
commit | 0d6fa033121a9bef708b8f2de186c4034c61d4a3 (patch) | |
tree | 851d65a09efbffa114c9a273e590d55cfb1436ab /spec/lib | |
parent | 0eb3d2f799ce4f4de87fb9fc6fd98e592323bc89 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 99 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/group_tree_restorer_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/runtime_spec.rb | 128 |
4 files changed, 62 insertions, 177 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 07fef203691..a9d7beb0fea 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -310,8 +310,8 @@ describe Gitlab::Git::Repository, :seed_helper do with_them do before do - repository.create_branch('left-branch', 'master') - repository.create_branch('right-branch', 'master') + repository.create_branch('left-branch') + repository.create_branch('right-branch') left.times do new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') @@ -350,8 +350,8 @@ describe Gitlab::Git::Repository, :seed_helper do with_them do before do - repository.create_branch('left-branch', 'master') - repository.create_branch('right-branch', 'master') + repository.create_branch('left-branch') + repository.create_branch('right-branch') left.times do new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') @@ -420,55 +420,6 @@ describe Gitlab::Git::Repository, :seed_helper do end end - describe "#delete_branch" do - let(:repository) { mutable_repository } - - after do - ensure_seeds - end - - it "removes the branch from the repo" do - branch_name = "to-be-deleted-soon" - - repository.create_branch(branch_name) - expect(repository_rugged.branches[branch_name]).not_to be_nil - - repository.delete_branch(branch_name) - expect(repository_rugged.branches[branch_name]).to be_nil - end - - context "when branch does not exist" do - it "raises a DeleteBranchError exception" do - expect { repository.delete_branch("this-branch-does-not-exist") }.to raise_error(Gitlab::Git::Repository::DeleteBranchError) - end - end - end - - describe "#create_branch" do - let(:repository) { mutable_repository } - - after do - ensure_seeds - end - - it "creates a new branch" do - expect(repository.create_branch('new_branch', 'master')).not_to be_nil - end - - it "creates a new branch with the right name" do - expect(repository.create_branch('another_branch', 'master').name).to eq('another_branch') - end - - it "fails if we create an existing branch" do - repository.create_branch('duplicated_branch', 'master') - expect {repository.create_branch('duplicated_branch', 'master')}.to raise_error("Branch duplicated_branch already exists") - end - - it "fails if we create a branch from a non existing ref" do - expect {repository.create_branch('branch_based_in_wrong_ref', 'master_2_the_revenge')}.to raise_error("Invalid reference master_2_the_revenge") - end - end - describe '#delete_refs' do let(:repository) { mutable_repository } @@ -506,8 +457,8 @@ describe Gitlab::Git::Repository, :seed_helper do let(:utf8_branch) { 'branch-é' } before do - repository.create_branch(new_branch, 'master') - repository.create_branch(utf8_branch, 'master') + repository.create_branch(new_branch) + repository.create_branch(utf8_branch) end after do @@ -609,32 +560,30 @@ describe Gitlab::Git::Repository, :seed_helper do describe '#search_files_by_content' do let(:repository) { mutable_repository } let(:repository_rugged) { mutable_repository_rugged } + let(:ref) { 'search-files-by-content-branch' } + let(:content) { 'foobarbazmepmep' } before do - repository.create_branch('search-files-by-content-branch', 'master') - new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'search-files-by-content-branch', 'committing something', 'search-files-by-content change') - new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', 'search-files-by-content-branch', 'committing something', 'search-files-by-content change') + repository.create_branch(ref) + new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', ref, 'committing something', content) + new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', ref, 'committing something', content) end after do ensure_seeds end - shared_examples 'search files by content' do - it 'has 2 items' do - expect(search_results.size).to eq(2) - end + subject do + repository.search_files_by_content(content, ref) + end - it 'has the correct matching line' do - expect(search_results).to contain_exactly("search-files-by-content-branch:encoding/CHANGELOG\u00001\u0000search-files-by-content change\n", - "search-files-by-content-branch:anotherfile\u00001\u0000search-files-by-content change\n") - end + it 'has 2 items' do + expect(subject.size).to eq(2) end - it_should_behave_like 'search files by content' do - let(:search_results) do - repository.search_files_by_content('search-files-by-content', 'search-files-by-content-branch') - end + it 'has the correct matching line' do + expect(subject).to contain_exactly("#{ref}:encoding/CHANGELOG\u00001\u0000#{content}\n", + "#{ref}:anotherfile\u00001\u0000#{content}\n") end end @@ -1116,7 +1065,7 @@ describe Gitlab::Git::Repository, :seed_helper do before do create_remote_branch('joe', 'remote_branch', 'master') - repository.create_branch('local_branch', 'master') + repository.create_branch('local_branch') end after do @@ -1142,7 +1091,7 @@ describe Gitlab::Git::Repository, :seed_helper do before do create_remote_branch('joe', 'remote_branch', 'master') - repository.create_branch('local_branch', 'master') + repository.create_branch('local_branch') end after do @@ -1192,7 +1141,7 @@ describe Gitlab::Git::Repository, :seed_helper do context 'when no branch names are specified' do before do - repository.create_branch('identical', 'master') + repository.create_branch('identical') end after do @@ -1303,7 +1252,7 @@ describe Gitlab::Git::Repository, :seed_helper do let(:branch_name) { "ʕ•ᴥ•ʔ" } before do - repository.create_branch(branch_name, "master") + repository.create_branch(branch_name) end after do @@ -1447,7 +1396,7 @@ describe Gitlab::Git::Repository, :seed_helper do before do create_remote_branch('joe', 'remote_branch', 'master') - repository.create_branch('local_branch', 'master') + repository.create_branch('local_branch') end after do diff --git a/spec/lib/gitlab/import_export/group_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group_tree_restorer_spec.rb index 0c55ed715cc..0d9b07ffaf0 100644 --- a/spec/lib/gitlab/import_export/group_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group_tree_restorer_spec.rb @@ -10,9 +10,9 @@ describe Gitlab::ImportExport::GroupTreeRestorer do describe 'restore group tree' do before(:context) do # Using an admin for import, so we can check assignment of existing members - user = create(:admin, username: 'root') - create(:user, username: 'adriene.mcclure') - create(:user, username: 'gwendolyn_robel') + user = create(:admin, email: 'root@gitlabexample.com') + create(:user, email: 'adriene.mcclure@gitlabexample.com') + create(:user, email: 'gwendolyn_robel@gitlabexample.com') RSpec::Mocks.with_temporary_scope do @group = create(:group, name: 'group', path: 'group') @@ -56,7 +56,7 @@ describe Gitlab::ImportExport::GroupTreeRestorer do end it 'has group members' do - expect(@group.members.map(&:user).map(&:username)).to contain_exactly('root', 'adriene.mcclure', 'gwendolyn_robel') + expect(@group.members.map(&:user).map(&:email)).to contain_exactly('root@gitlabexample.com', 'adriene.mcclure@gitlabexample.com', 'gwendolyn_robel@gitlabexample.com') end end end diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 129f119e148..c899217d164 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -13,8 +13,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do # Using an admin for import, so we can check assignment of existing members @user = create(:admin) @existing_members = [ - create(:user, username: 'bernard_willms'), - create(:user, username: 'saul_will') + create(:user, email: 'bernard_willms@gitlabexample.com'), + create(:user, email: 'saul_will@gitlabexample.com') ] RSpec::Mocks.with_temporary_scope do diff --git a/spec/lib/gitlab/runtime_spec.rb b/spec/lib/gitlab/runtime_spec.rb index 52976d925b9..f6e8ad8ae79 100644 --- a/spec/lib/gitlab/runtime_spec.rb +++ b/spec/lib/gitlab/runtime_spec.rb @@ -3,6 +3,23 @@ require 'spec_helper' describe Gitlab::Runtime do + shared_examples "valid runtime" do |runtime, max_threads| + it "identifies itself" do + expect(subject.identify).to eq(runtime) + expect(subject.public_send("#{runtime}?")).to be(true) + end + + it "does not identify as others" do + (described_class::AVAILABLE_RUNTIMES - [runtime]).each do |runtime| + expect(subject.public_send("#{runtime}?")).to eq(false) + end + end + + it "reports its maximum concurrency" do + expect(subject.max_threads).to eq(max_threads) + end + end + before do allow(described_class).to receive(:process_name).and_return('ruby') stub_rails_env('production') @@ -27,117 +44,42 @@ describe Gitlab::Runtime do context "puma" do let(:puma_type) { double('::Puma') } - let(:options) do - { - max_threads: 2 - } - end before do stub_const('::Puma', puma_type) - allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(options) - end - - it "identifies itself" do - expect(subject.identify).to eq(:puma) - expect(subject.puma?).to be(true) + allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2) end - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.console?).to be(false) - expect(subject.rake?).to be(false) - expect(subject.test_suite?).to be(false) - end - - it "reports its maximum concurrency" do - expect(subject.max_threads).to eq(2) - end + it_behaves_like "valid runtime", :puma, 2 end context "unicorn" do - let(:unicorn_type) { Module.new } - let(:unicorn_server_type) { Class.new } - before do - stub_const('::Unicorn', unicorn_type) - stub_const('::Unicorn::HttpServer', unicorn_server_type) + stub_const('::Unicorn', Module.new) + stub_const('::Unicorn::HttpServer', Class.new) end - it "identifies itself" do - expect(subject.identify).to eq(:unicorn) - expect(subject.unicorn?).to be(true) - end - - it "does not identify as others" do - expect(subject.puma?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.console?).to be(false) - expect(subject.rake?).to be(false) - expect(subject.test_suite?).to be(false) - end - - it "reports its maximum concurrency" do - expect(subject.max_threads).to eq(1) - end + it_behaves_like "valid runtime", :unicorn, 1 end context "sidekiq" do let(:sidekiq_type) { double('::Sidekiq') } - let(:options) do - { - concurrency: 2 - } - end before do stub_const('::Sidekiq', sidekiq_type) allow(sidekiq_type).to receive(:server?).and_return(true) - allow(sidekiq_type).to receive(:options).and_return(options) + allow(sidekiq_type).to receive(:options).and_return(concurrency: 2) end - it "identifies itself" do - expect(subject.identify).to eq(:sidekiq) - expect(subject.sidekiq?).to be(true) - end - - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.puma?).to be(false) - expect(subject.console?).to be(false) - expect(subject.rake?).to be(false) - expect(subject.test_suite?).to be(false) - end - - it "reports its maximum concurrency" do - expect(subject.max_threads).to eq(2) - end + it_behaves_like "valid runtime", :sidekiq, 2 end context "console" do - let(:console_type) { double('::Rails::Console') } - before do - stub_const('::Rails::Console', console_type) - end - - it "identifies itself" do - expect(subject.identify).to eq(:console) - expect(subject.console?).to be(true) - end - - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.puma?).to be(false) - expect(subject.rake?).to be(false) - expect(subject.test_suite?).to be(false) + stub_const('::Rails::Console', double('::Rails::Console')) end - it "reports its maximum concurrency" do - expect(subject.max_threads).to eq(1) - end + it_behaves_like "valid runtime", :console, 1 end context "test suite" do @@ -145,20 +87,14 @@ describe Gitlab::Runtime do stub_rails_env('test') end - it "identifies itself" do - expect(subject.identify).to eq(:test_suite) - expect(subject.test_suite?).to be(true) - end + it_behaves_like "valid runtime", :test_suite, 1 + end - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.rake?).to be(false) - expect(subject.puma?).to be(false) + context "geo log cursor" do + before do + stub_const('::GeoLogCursorOptionParser', double('::GeoLogCursorOptionParser')) end - it "reports its maximum concurrency" do - expect(subject.max_threads).to eq(1) - end + it_behaves_like "valid runtime", :geo_log_cursor, 1 end end |