diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 09:10:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 09:10:02 +0300 |
commit | 2000704b7a6cc9eb37dd597ed03567265eda9308 (patch) | |
tree | bf52d4b9b4d5420a6e2b2974f34326e0eda8a25f /qa | |
parent | f6dad4cfc60d81a00c5ef33b7680d3cca4393e29 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa.rb | 1 | ||||
-rw-r--r-- | qa/qa/resource/base.rb | 2 | ||||
-rw-r--r-- | qa/qa/resource/bulk_import_group.rb | 76 | ||||
-rw-r--r-- | qa/qa/specs/features/api/1_manage/bulk_import_group_spec.rb | 104 | ||||
-rw-r--r-- | qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb | 46 | ||||
-rw-r--r-- | qa/spec/resource/base_spec.rb | 6 |
6 files changed, 192 insertions, 43 deletions
@@ -73,6 +73,7 @@ module QA autoload :GroupBase, 'qa/resource/group_base' autoload :Sandbox, 'qa/resource/sandbox' autoload :Group, 'qa/resource/group' + autoload :BulkImportGroup, 'qa/resource/bulk_import_group' autoload :Issue, 'qa/resource/issue' autoload :ProjectIssueNote, 'qa/resource/project_issue_note' autoload :Project, 'qa/resource/project' diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb index 88b388bd2e0..2848e3ba7d2 100644 --- a/qa/qa/resource/base.rb +++ b/qa/qa/resource/base.rb @@ -188,7 +188,7 @@ module QA end def log_having_both_api_result_and_block(name, api_value) - QA::Runtime::Logger.info(<<~MSG.strip) + QA::Runtime::Logger.debug(<<~MSG.strip) <#{self.class}> Attribute #{name.inspect} has both API response `#{api_value}` and a block. API response will be picked. Block will be ignored. MSG end diff --git a/qa/qa/resource/bulk_import_group.rb b/qa/qa/resource/bulk_import_group.rb new file mode 100644 index 00000000000..5a7041d9f77 --- /dev/null +++ b/qa/qa/resource/bulk_import_group.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +module QA + module Resource + class BulkImportGroup < Group + attributes :source_group_path, + :import_id + + attribute :destination_group_path do + source_group_path + end + + attribute :access_token do + api_client.personal_access_token + end + + alias_method :path, :source_group_path + + delegate :gitlab_address, to: 'QA::Runtime::Scenario' + + def fabricate_via_browser_ui! + Page::Main::Menu.perform(&:go_to_create_group) + + Page::Group::New.perform do |group| + group.switch_to_import_tab + group.connect_gitlab_instance(gitlab_address, api_client.personal_access_token) + end + + Page::Group::BulkImport.perform do |import_page| + import_page.import_group(path, sandbox.path) + end + + reload! + visit! + end + + def fabricate_via_api! + response = post(Runtime::API::Request.new(api_client, api_post_path).url, api_post_body) + @import_id = parse_body(response)[:id] + + "#{gitlab_address}/#{full_path}" + end + + def api_post_path + '/bulk_imports' + end + + def api_post_body + { + configuration: { + url: gitlab_address, + access_token: access_token + }, + entities: [ + { + source_type: 'group_entity', + source_full_path: source_group_path, + destination_name: destination_group_path, + destination_namespace: sandbox.path + } + ] + } + end + + def import_status + response = get(Runtime::API::Request.new(api_client, "/bulk_imports/#{import_id}").url) + + unless response.code == HTTP_STATUS_OK + raise ResourceQueryError, "Could not get import status. Request returned (#{response.code}): `#{response}`." + end + + parse_body(response)[:status] + end + end + end +end diff --git a/qa/qa/specs/features/api/1_manage/bulk_import_group_spec.rb b/qa/qa/specs/features/api/1_manage/bulk_import_group_spec.rb new file mode 100644 index 00000000000..2ace3f13217 --- /dev/null +++ b/qa/qa/specs/features/api/1_manage/bulk_import_group_spec.rb @@ -0,0 +1,104 @@ +# frozen_string_literal: true + +module QA + RSpec.describe 'Manage', :requires_admin do + describe 'Bulk group import via api' do + let!(:staging?) { Runtime::Scenario.gitlab_address.include?('staging.gitlab.com') } + + let(:admin_api_client) { Runtime::API::Client.as_admin } + let(:user) do + Resource::User.fabricate_via_api! do |usr| + usr.api_client = admin_api_client + usr.hard_delete_on_api_removal = true + end + end + + let(:api_client) { Runtime::API::Client.new(user: user) } + let(:personal_access_token) { api_client.personal_access_token } + + let(:sandbox) do + Resource::Sandbox.fabricate_via_api! do |group| + group.api_client = admin_api_client + end + end + + let(:source_group) do + Resource::Sandbox.fabricate_via_api! do |group| + group.api_client = api_client + group.path = "source-group-for-import-#{SecureRandom.hex(4)}" + end + end + + let(:subgroup) do + Resource::Group.fabricate_via_api! do |group| + group.api_client = api_client + group.sandbox = source_group + group.path = "subgroup-for-import-#{SecureRandom.hex(4)}" + end + end + + let(:imported_subgroup) do + Resource::Group.init do |group| + group.api_client = api_client + group.sandbox = imported_group + group.path = subgroup.path + end + end + + let(:imported_group) do + Resource::BulkImportGroup.fabricate_via_api! do |group| + group.api_client = api_client + group.sandbox = sandbox + group.source_group_path = source_group.path + end + end + + before do + Runtime::Feature.enable(:bulk_import) unless staging? + Runtime::Feature.enable(:top_level_group_creation_enabled) if staging? + + sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER) + + Resource::GroupLabel.fabricate_via_api! do |label| + label.api_client = api_client + label.group = source_group + label.title = "source-group-#{SecureRandom.hex(4)}" + end + Resource::GroupLabel.fabricate_via_api! do |label| + label.api_client = api_client + label.group = subgroup + label.title = "subgroup-#{SecureRandom.hex(4)}" + end + end + + # Non blocking issues: + # https://gitlab.com/gitlab-org/gitlab/-/issues/331252 + # https://gitlab.com/gitlab-org/gitlab/-/issues/333678 <- can cause 500 when creating user and group back to back + it( + 'imports group with subgroups and labels', + testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1871' + ) do + Page::Group::BulkImport.perform do |import_page| + imported_group + + expect { imported_group.import_status }.to eventually_eq('finished').within(duration: 300, interval: 2) + + aggregate_failures do + expect(imported_group.reload!).to eq(source_group) + expect(imported_group.labels).to include(*source_group.labels) + + expect(imported_subgroup.reload!).to eq(subgroup) + expect(imported_subgroup.labels).to include(*subgroup.labels) + end + end + end + + after do + user.remove_via_api! + ensure + Runtime::Feature.disable(:bulk_import) unless staging? + Runtime::Feature.disable(:top_level_group_creation_enabled) if staging? + end + end + end +end diff --git a/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb b/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb index 4fee7e6d07f..f54bdf0449c 100644 --- a/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb +++ b/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb @@ -29,27 +29,11 @@ module QA end end - let(:subgroup) do - Resource::Group.fabricate_via_api! do |group| - group.api_client = api_client - group.sandbox = source_group - group.path = "subgroup-for-import-#{SecureRandom.hex(4)}" - end - end - let(:imported_group) do - Resource::Group.init do |group| + Resource::BulkImportGroup.init do |group| group.api_client = api_client group.sandbox = sandbox - group.path = source_group.path - end - end - - let(:imported_subgroup) do - Resource::Group.init do |group| - group.api_client = api_client - group.sandbox = imported_group - group.path = subgroup.path + group.source_group_path = source_group.path end end @@ -61,7 +45,6 @@ module QA # create groups explicitly before connecting gitlab instance source_group - subgroup Flow::Login.sign_in(as: user) Page::Main::Menu.perform(&:go_to_create_group) @@ -78,29 +61,14 @@ module QA 'imports group with subgroups and labels', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785' ) do - Resource::GroupLabel.fabricate_via_api! do |label| - label.api_client = api_client - label.group = source_group - label.title = "source-group-#{SecureRandom.hex(4)}" - end - Resource::GroupLabel.fabricate_via_api! do |label| - label.api_client = api_client - label.group = subgroup - label.title = "subgroup-#{SecureRandom.hex(4)}" - end - Page::Group::BulkImport.perform do |import_page| - import_page.import_group(source_group.path, sandbox.path) - - expect(import_page).to have_imported_group(source_group.path, wait: 300) + import_page.import_group(imported_group.path, imported_group.sandbox.path) - aggregate_failures do - expect { imported_group.reload! }.to eventually_eq(source_group).within(duration: 10) - expect { imported_group.labels }.to eventually_include(*source_group.labels).within(duration: 10) + expect(import_page).to have_imported_group(imported_group.path, wait: 300) - # Do not validate subgroups until https://gitlab.com/gitlab-org/gitlab/-/issues/332818 is resolved - # expect { imported_subgroup.reload! }.to eventually_eq(subgroup).within(duration: 30) - # expect { imported_subgroup.labels }.to eventually_include(*subgroup.labels).within(duration: 30) + imported_group.reload!.visit! + Page::Group::Show.perform do |group| + expect(group).to have_content(imported_group.path) end end end diff --git a/qa/spec/resource/base_spec.rb b/qa/spec/resource/base_spec.rb index a60bb3e6eaf..c6dd56b5f47 100644 --- a/qa/spec/resource/base_spec.rb +++ b/qa/spec/resource/base_spec.rb @@ -170,16 +170,16 @@ RSpec.describe QA::Resource::Base do let(:api_resource) { { test: 'api_with_block' } } before do - allow(QA::Runtime::Logger).to receive(:info) + allow(QA::Runtime::Logger).to receive(:debug) end - it 'returns value from api and emits an INFO log entry' do + it 'returns value from api and emits an debug log entry' do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.test).to eq('api_with_block') expect(QA::Runtime::Logger) - .to have_received(:info).with(/api_with_block/) + .to have_received(:debug).with(/api_with_block/) end end end |