Commit 8f6c47f0 authored by Andrejs Cunskis's avatar Andrejs Cunskis Committed by Dan Davison

E2E: Validate subgroup migration

parent 61e1a40a
......@@ -65,6 +65,7 @@ module QA
autoload :ApiFabricator, 'qa/resource/api_fabricator'
autoload :Base, 'qa/resource/base'
autoload :GroupBase, 'qa/resource/group_base'
autoload :Sandbox, 'qa/resource/sandbox'
autoload :Group, 'qa/resource/group'
autoload :Issue, 'qa/resource/issue'
......
......@@ -2,10 +2,8 @@
module QA
module Resource
class Group < Base
include Members
attr_accessor :path, :description
class Group < GroupBase
attr_accessor :description
attribute :sandbox do
Sandbox.fabricate_via_api! do |sandbox|
......@@ -13,10 +11,6 @@ module QA
end
end
attribute :full_path
attribute :id
attribute :name
attribute :runners_token
attribute :require_two_factor_authentication
def initialize
......@@ -59,14 +53,6 @@ module QA
"/groups/#{CGI.escape("#{sandbox.path}/#{path}")}"
end
def api_put_path
"/groups/#{id}"
end
def api_post_path
'/groups'
end
def api_post_body
{
parent_id: sandbox.id,
......@@ -77,17 +63,14 @@ module QA
}
end
def api_delete_path
"/groups/#{id}"
end
def set_require_two_factor_authentication(value:)
put_body = { require_two_factor_authentication: value }
response = put Runtime::API::Request.new(api_client, api_put_path).url, put_body
return if response.code == HTTP_STATUS_OK
unless response.code == HTTP_STATUS_OK
raise ResourceUpdateFailedError, "Could not update require_two_factor_authentication to #{value}. Request returned (#{response.code}): `#{response}`."
end
raise(ResourceUpdateFailedError, <<~ERROR.strip)
Could not update require_two_factor_authentication to #{value}. Request returned (#{response.code}): `#{response}`.
ERROR
end
def change_repository_storage(new_storage)
......@@ -95,12 +78,20 @@ module QA
response = post Runtime::API::Request.new(api_client, "/groups/#{id}/repository_storage_moves").url, post_body
unless response.code.between?(200, 300)
raise ResourceUpdateFailedError, "Could not change repository storage to #{new_storage}. Request returned (#{response.code}): `#{response}`."
raise(
ResourceUpdateFailedError,
"Could not change repository storage to #{new_storage}. Request returned (#{response.code}): `#{response}`."
)
end
wait_until(sleep_interval: 1) { Runtime::API::RepositoryStorageMoves.has_status?(self, 'finished', new_storage) }
wait_until(sleep_interval: 1) do
Runtime::API::RepositoryStorageMoves.has_status?(self, 'finished', new_storage)
end
rescue Support::Repeater::RepeaterConditionExceededError
raise Runtime::API::RepositoryStorageMoves::RepositoryStorageMovesError, 'Timed out while waiting for the group repository storage move to finish'
raise(
Runtime::API::RepositoryStorageMoves::RepositoryStorageMovesError,
'Timed out while waiting for the group repository storage move to finish'
)
end
end
end
......
# frozen_string_literal: true
module QA
module Resource
# Base class for group classes Resource::Sandbox and Resource::Group
#
class GroupBase < Base
include Members
attr_accessor :path
attribute :id
attribute :runners_token
attribute :name
attribute :full_path
# API post path
#
# @return [String]
def api_post_path
'/groups'
end
# API put path
#
# @return [String]
def api_put_path
"/groups/#{id}"
end
# API delete path
#
# @return [String]
def api_delete_path
"/groups/#{id}"
end
# Object comparison
#
# @param [QA::Resource::GroupBase] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupBase) && comparable_group == other.comparable_group
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_group)
end
protected
# Return subset of fields for comparing groups
#
# @return [Hash]
def comparable_group
reload! if api_response.nil?
api_resource.except(
:id,
:web_url,
:visibility,
:full_name,
:full_path,
:created_at,
:parent_id,
:runners_token
)
end
end
end
end
......@@ -6,16 +6,7 @@ module QA
# Ensure we're in our sandbox namespace, either by navigating to it or by
# creating it if it doesn't yet exist.
#
class Sandbox < Base
include Members
attr_accessor :path
attribute :id
attribute :runners_token
attribute :name
attribute :full_path
class Sandbox < GroupBase
def initialize
@path = Runtime::Namespace.sandbox_name
end
......@@ -56,18 +47,6 @@ module QA
"/groups/#{path}"
end
def api_members_path
"#{api_get_path}/members"
end
def api_post_path
'/groups'
end
def api_delete_path
"/groups/#{id}"
end
def api_post_body
{
path: path,
......@@ -76,17 +55,14 @@ module QA
}
end
def api_put_path
"/groups/#{id}"
end
def update_group_setting(group_setting:, value:)
put_body = { "#{group_setting}": value }
response = put Runtime::API::Request.new(api_client, api_put_path).url, put_body
response = put(Runtime::API::Request.new(api_client, api_put_path).url, { "#{group_setting}": value })
return if response.code == HTTP_STATUS_OK
unless response.code == HTTP_STATUS_OK
raise ResourceUpdateFailedError, "Could not update #{group_setting} to #{value}. Request returned (#{response.code}): `#{response}`."
end
raise(
ResourceUpdateFailedError,
"Could not update #{group_setting} to #{value}. Request returned (#{response.code}): `#{response}`."
)
end
end
end
......
......@@ -26,30 +26,27 @@ 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.new.tap do |group|
group.api_client = api_client
group.path = source_group.path
end.reload!
rescue Resource::ApiFabricator::ResourceNotFoundError
nil
end
end
# Return subset of fields for comparing groups
#
# @param [Resource::Group, nil] group
# @return [Hash]
def comparable_group(group)
group&.api_resource&.except(
:id,
:web_url,
:visibility,
:full_name,
:full_path,
:created_at,
:parent_id,
:runners_token
)
let(:imported_subgroup) do
Resource::Group.new.tap do |group|
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
end
end
def staging?
......@@ -73,15 +70,15 @@ module QA
it(
'performs bulk group import from another gitlab instance',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785',
# https://gitlab.com/gitlab-org/gitlab/-/issues/330344
exclude: { job: ['ce:relative_url', 'ee:relative_url'] }
exclude: { job: ['ce:relative_url', 'ee:relative_url'] } # https://gitlab.com/gitlab-org/gitlab/-/issues/330344
) do
Page::Group::BulkImport.perform do |import_page|
import_page.import_group(source_group.path, sandbox.path)
aggregate_failures do
expect(import_page).to have_imported_group(source_group.path, wait: 120)
expect(comparable_group(imported_group)).to eq(comparable_group(source_group))
expect(imported_group).to eq(source_group)
expect(imported_subgroup).to eq(subgroup)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment