diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 12:10:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 12:10:45 +0300 |
commit | cd40f83527ac4ed4751b4b7849f0416996589d18 (patch) | |
tree | 201a36d826fc98f14ee1a7a1dc806b32f51cac00 /qa | |
parent | d5f3372f10b9fefc8cf831515152eee7ae908f69 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/page/component/note.rb | 3 | ||||
-rw-r--r-- | qa/qa/resource/snippet.rb | 27 | ||||
-rw-r--r-- | qa/qa/runtime/api/repository_storage_moves.rb | 22 | ||||
-rw-r--r-- | qa/qa/specs/features/api/3_create/snippet/snippet_repository_storage_move_spec.rb | 45 | ||||
-rw-r--r-- | qa/qa/support/api.rb | 1 |
5 files changed, 91 insertions, 7 deletions
diff --git a/qa/qa/page/component/note.rb b/qa/qa/page/component/note.rb index 50567796bdb..67583f71bf3 100644 --- a/qa/qa/page/component/note.rb +++ b/qa/qa/page/component/note.rb @@ -17,7 +17,6 @@ module QA element :comment_button element :comment_field element :discussion_menu_item - element :note_dropdown end base.view 'app/assets/javascripts/notes/components/discussion_actions.vue' do @@ -146,7 +145,7 @@ module QA def start_discussion(text) fill_element :comment_field, text - click_element :note_dropdown + within_element(:comment_button) { click_button(class: 'dropdown-toggle-split') } click_element :discussion_menu_item click_element :comment_button diff --git a/qa/qa/resource/snippet.rb b/qa/qa/resource/snippet.rb index 253a3363511..6423dc7a41c 100644 --- a/qa/qa/resource/snippet.rb +++ b/qa/qa/resource/snippet.rb @@ -6,6 +6,7 @@ module QA attr_accessor :title, :description, :file_content, :visibility, :file_name attribute :id + attribute :http_url_to_repo def initialize @title = 'New snippet title' @@ -53,6 +54,10 @@ module QA '/snippets' end + def api_put_path + "/snippets/#{id}" + end + def api_post_body { title: title, @@ -72,6 +77,28 @@ module QA file[:file_path] = file.delete(:name) end end + + def has_file?(file_path) + response = get Runtime::API::Request.new(api_client, api_get_path).url + + raise ResourceNotFoundError, "Request returned (#{response.code}): `#{response}`." if response.code == HTTP_STATUS_NOT_FOUND + + file_output = parse_body(response)[:files] + file_output.any? { |file| file[:path] == file_path } + end + + def change_repository_storage(new_storage) + post_body = { destination_storage_name: new_storage } + response = post Runtime::API::Request.new(api_client, "/snippets/#{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}`." + end + + wait_until(sleep_interval: 1) { Runtime::API::RepositoryStorageMoves.has_status?(self, 'finished', new_storage) } + rescue Support::Repeater::RepeaterConditionExceededError + raise Runtime::API::RepositoryStorageMoves::RepositoryStorageMovesError, 'Timed out while waiting for the snippet repository storage move to finish' + end end end end diff --git a/qa/qa/runtime/api/repository_storage_moves.rb b/qa/qa/runtime/api/repository_storage_moves.rb index d0211d3f66d..5630a9c02c5 100644 --- a/qa/qa/runtime/api/repository_storage_moves.rb +++ b/qa/qa/runtime/api/repository_storage_moves.rb @@ -9,9 +9,9 @@ module QA RepositoryStorageMovesError = Class.new(RuntimeError) - def has_status?(project, status, destination_storage = Env.additional_repository_storage) - find_any do |move| - next unless move[:project][:path_with_namespace] == project.path_with_namespace + def has_status?(resource, status, destination_storage = Env.additional_repository_storage) + find_any(resource) do |move| + next unless resource_equals?(resource, move) QA::Runtime::Logger.debug("Move data: #{move}") @@ -20,16 +20,28 @@ module QA end end - def find_any + def find_any(resource) Logger.debug('Getting repository storage moves') Support::Waiter.wait_until do - with_paginated_response_body(Request.new(api_client, '/project_repository_storage_moves', per_page: '100').url) do |page| + with_paginated_response_body(Request.new(api_client, "/#{resource_name(resource)}_repository_storage_moves", per_page: '100').url) do |page| break true if page.any? { |item| yield item } end end end + def resource_equals?(resource, move) + if resource.class.name.include?('Snippet') + move[:snippet][:id] == resource.id + else + move[:project][:path_with_namespace] == resource.path_with_namespace + end + end + + def resource_name(resource) + resource.class.name.split('::').last.downcase + end + private def api_client diff --git a/qa/qa/specs/features/api/3_create/snippet/snippet_repository_storage_move_spec.rb b/qa/qa/specs/features/api/3_create/snippet/snippet_repository_storage_move_spec.rb new file mode 100644 index 00000000000..4872acd1004 --- /dev/null +++ b/qa/qa/specs/features/api/3_create/snippet/snippet_repository_storage_move_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module QA + RSpec.describe 'Create' do + describe 'Snippet repository storage', :requires_admin, :orchestrated, :repository_storage do + let(:source_storage) { { type: :gitaly, name: 'default' } } + let(:destination_storage) { { type: :gitaly, name: QA::Runtime::Env.additional_repository_storage } } + + let(:snippet) do + Resource::Snippet.fabricate_via_api! do |snippet| + snippet.title = 'Snippet to move storage of' + snippet.file_name = 'original_file' + snippet.file_content = 'Original file content' + snippet.api_client = Runtime::API::Client.as_admin + end + end + + praefect_manager = Service::PraefectManager.new + + before do + praefect_manager.gitlab = 'gitlab' + end + + it 'moves snippet repository from one Gitaly storage to another', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1700' do + expect(snippet).to have_file('original_file') + expect { snippet.change_repository_storage(destination_storage[:name]) }.not_to raise_error + expect { praefect_manager.verify_storage_move(source_storage, destination_storage) }.not_to raise_error + + # verifies you can push commits to the moved snippet + Resource::Repository::Push.fabricate! do |push| + push.repository_http_uri = snippet.http_url_to_repo + push.file_name = 'new_file' + push.file_content = 'new file content' + push.commit_message = 'Adding a new snippet file' + push.new_branch = false + end + + aggregate_failures do + expect(snippet).to have_file('original_file') + expect(snippet).to have_file('new_file') + end + end + end + end +end diff --git a/qa/qa/support/api.rb b/qa/qa/support/api.rb index 5fc36b68e5c..de9da3171b0 100644 --- a/qa/qa/support/api.rb +++ b/qa/qa/support/api.rb @@ -9,6 +9,7 @@ module QA HTTP_STATUS_CREATED = 201 HTTP_STATUS_NO_CONTENT = 204 HTTP_STATUS_ACCEPTED = 202 + HTTP_STATUS_NOT_FOUND = 404 HTTP_STATUS_SERVER_ERROR = 500 def post(url, payload, args = {}) |