diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /qa/qa/resource | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'qa/qa/resource')
-rw-r--r-- | qa/qa/resource/group.rb | 5 | ||||
-rw-r--r-- | qa/qa/resource/issue.rb | 4 | ||||
-rw-r--r-- | qa/qa/resource/project.rb | 36 | ||||
-rw-r--r-- | qa/qa/resource/project_milestone.rb | 7 | ||||
-rw-r--r-- | qa/qa/resource/project_snippet.rb | 29 | ||||
-rw-r--r-- | qa/qa/resource/protected_branch.rb | 33 | ||||
-rw-r--r-- | qa/qa/resource/repository/project_push.rb | 4 | ||||
-rw-r--r-- | qa/qa/resource/repository/push.rb | 6 | ||||
-rw-r--r-- | qa/qa/resource/repository/wiki_push.rb | 17 | ||||
-rw-r--r-- | qa/qa/resource/sandbox.rb | 1 | ||||
-rw-r--r-- | qa/qa/resource/ssh_key.rb | 17 | ||||
-rw-r--r-- | qa/qa/resource/wiki.rb | 48 | ||||
-rw-r--r-- | qa/qa/resource/wiki/project_page.rb | 68 |
13 files changed, 193 insertions, 82 deletions
diff --git a/qa/qa/resource/group.rb b/qa/qa/resource/group.rb index a30bb8cbc77..850d6205305 100644 --- a/qa/qa/resource/group.rb +++ b/qa/qa/resource/group.rb @@ -14,6 +14,7 @@ module QA end end + attribute :full_path attribute :id attribute :name attribute :runners_token @@ -74,10 +75,6 @@ module QA def api_delete_path "/groups/#{id}" end - - def full_path - sandbox.path + ' / ' + path - end end end end diff --git a/qa/qa/resource/issue.rb b/qa/qa/resource/issue.rb index 0817a9de06f..b4295a35263 100644 --- a/qa/qa/resource/issue.rb +++ b/qa/qa/resource/issue.rb @@ -32,8 +32,8 @@ module QA Page::Project::Show.perform(&:go_to_new_issue) Page::Project::Issue::New.perform do |new_page| - new_page.add_title(@title) - new_page.add_description(@description) + new_page.fill_title(@title) + new_page.fill_description(@description) new_page.create_new_issue end end diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb index 78e2ba8a248..645f4e97ee0 100644 --- a/qa/qa/resource/project.rb +++ b/qa/qa/resource/project.rb @@ -30,6 +30,8 @@ module QA "#{sandbox_path}#{group.path}/#{name}" if group end + alias_method :full_path, :path_with_namespace + def sandbox_path group.respond_to?('sandbox') ? "#{group.sandbox.path}/" : '' end @@ -54,6 +56,8 @@ module QA @auto_devops_enabled = false @visibility = :public @template_name = nil + + self.name = "the_awesome_project" end def name=(raw_name) @@ -67,12 +71,14 @@ module QA end if @template_name + QA::Flow::Project.go_to_create_project_from_template Page::Project::New.perform do |new_page| - new_page.click_create_from_template_tab new_page.use_template_for_project(@template_name) end end + Page::Project::NewExperiment.perform(&:click_blank_project_link) if Page::Project::NewExperiment.perform(&:shown?) + Page::Project::New.perform do |new_page| new_page.choose_test_namespace new_page.choose_name(@name) @@ -89,6 +95,10 @@ module QA super end + def has_file?(file_path) + repository_tree.any? { |file| file[:path] == file_path } + end + def api_get_path "/projects/#{CGI.escape(path_with_namespace)}" end @@ -109,6 +119,14 @@ module QA "#{api_get_path}/runners" end + def api_repository_branches_path + "#{api_get_path}/repository/branches" + end + + def api_repository_tree_path + "#{api_get_path}/repository/tree" + end + def api_pipelines_path "#{api_get_path}/pipelines" end @@ -149,11 +167,9 @@ module QA raise ResourceUpdateFailedError, "Could not change repository storage to #{new_storage}. Request returned (#{response.code}): `#{response}`." end - wait_until do - reload! - - api_response[:repository_storage] == new_storage - 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 repository storage move to finish' end def import_status @@ -180,6 +196,14 @@ module QA parse_body(response) end + def repository_branches + parse_body(get(Runtime::API::Request.new(api_client, api_repository_branches_path).url)) + end + + def repository_tree + parse_body(get(Runtime::API::Request.new(api_client, api_repository_tree_path).url)) + end + def pipelines parse_body(get(Runtime::API::Request.new(api_client, api_pipelines_path).url)) end diff --git a/qa/qa/resource/project_milestone.rb b/qa/qa/resource/project_milestone.rb index 4d6b37937b4..385b9f0c96b 100644 --- a/qa/qa/resource/project_milestone.rb +++ b/qa/qa/resource/project_milestone.rb @@ -3,6 +3,8 @@ module QA module Resource class ProjectMilestone < Base + attr_writer :start_date, :due_date + attribute :id attribute :title @@ -27,7 +29,10 @@ module QA def api_post_body { title: title - } + }.tap do |hash| + hash[:start_date] = @start_date if @start_date + hash[:due_date] = @due_date if @due_date + end end end end diff --git a/qa/qa/resource/project_snippet.rb b/qa/qa/resource/project_snippet.rb new file mode 100644 index 00000000000..ce4be6445f1 --- /dev/null +++ b/qa/qa/resource/project_snippet.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module QA + module Resource + class ProjectSnippet < Snippet + attribute :project do + Project.fabricate_via_api! do |resource| + resource.name = 'project-with-snippets' + end + end + + def fabricate! + project.visit! + + Page::Project::Menu.perform { |sidebar| sidebar.click_snippets } + + Page::Project::Snippet::New.perform do |new_snippet| + new_snippet.click_create_first_snippet + new_snippet.fill_title(@title) + new_snippet.fill_description(@description) + new_snippet.set_visibility(@visibility) + new_snippet.fill_file_name(@file_name) + new_snippet.fill_file_content(@file_content) + new_snippet.click_create_snippet_button + end + end + end + end +end diff --git a/qa/qa/resource/protected_branch.rb b/qa/qa/resource/protected_branch.rb index 9c65e0e5a31..9b728fc4c24 100644 --- a/qa/qa/resource/protected_branch.rb +++ b/qa/qa/resource/protected_branch.rb @@ -5,7 +5,12 @@ require 'securerandom' module QA module Resource class ProtectedBranch < Base - attr_accessor :branch_name, :allowed_to_push, :allowed_to_merge, :protected + attr_accessor :branch_name, + :allowed_to_push, + :allowed_to_merge, + :protected, + :new_branch, + :require_code_owner_approval attribute :project do Project.fabricate_via_api! do |resource| @@ -21,11 +26,12 @@ module QA project_push.commit_message = 'Add new file' project_push.branch_name = branch_name project_push.new_branch = true - project_push.remote_branch = @branch_name + project_push.remote_branch = branch_name end end def initialize + @new_branch = true @branch_name = 'test/branch' @allowed_to_push = { roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS @@ -34,22 +40,29 @@ module QA roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS } @protected = false + @require_code_owner_approval = true end def fabricate! - populate(:branch) + if new_branch + populate(:branch) - project.wait_for_push_new_branch @branch_name + project.wait_for_push_new_branch branch_name + end project.visit! Page::Project::Menu.perform(&:go_to_repository_settings) Page::Project::Settings::Repository.perform do |setting| setting.expand_protected_branches do |page| - page.select_branch(branch_name) - page.select_allowed_to_merge(allowed_to_merge) - page.select_allowed_to_push(allowed_to_push) - page.protect_branch + if new_branch + page.select_branch(branch_name) + page.select_allowed_to_merge(allowed_to_merge) + page.select_allowed_to_push(allowed_to_push) + page.protect_branch + else + page.require_code_owner_approval(branch_name) if require_code_owner_approval + end end end end @@ -59,11 +72,11 @@ module QA end def api_get_path - "/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}" + "/projects/#{project.id}/protected_branches/#{branch_name}" end def api_delete_path - "/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}" + "/projects/#{project.id}/protected_branches/#{branch_name}" end class Roles diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb index 17596601cf9..c46921ad0c7 100644 --- a/qa/qa/resource/repository/project_push.rb +++ b/qa/qa/resource/repository/project_push.rb @@ -9,8 +9,11 @@ module QA attr_accessor :project_name attr_writer :wait_for_push + attribute :group + attribute :project do Project.fabricate! do |resource| + resource.group = group if @group resource.name = project_name resource.description = 'Project with repository' end @@ -24,6 +27,7 @@ module QA @new_branch = true @project_name = 'project-with-code' @wait_for_push = true + @group = nil end def repository_http_uri diff --git a/qa/qa/resource/repository/push.rb b/qa/qa/resource/repository/push.rb index 902ae9f3135..1e5399fcc59 100644 --- a/qa/qa/resource/repository/push.rb +++ b/qa/qa/resource/repository/push.rb @@ -60,13 +60,13 @@ module QA repository.use_lfs = use_lfs - username = 'GitLab QA' + name = 'GitLab QA' email = 'root@gitlab.com' if user repository.username = user.username repository.password = user.password - username = user.name + name = user.name email = user.email end @@ -75,7 +75,7 @@ module QA end @output += repository.clone - repository.configure_identity(username, email) + repository.configure_identity(name, email) @output += repository.checkout(branch_name, new_branch: new_branch) diff --git a/qa/qa/resource/repository/wiki_push.rb b/qa/qa/resource/repository/wiki_push.rb index e926c00d380..edf76c7cd78 100644 --- a/qa/qa/resource/repository/wiki_push.rb +++ b/qa/qa/resource/repository/wiki_push.rb @@ -5,17 +5,17 @@ module QA module Repository class WikiPush < Repository::Push attribute :wiki do - Wiki.fabricate! do |resource| + # We are using the project based wiki as a standard. + Wiki::ProjectPage.fabricate_via_api! do |resource| resource.title = 'Home' resource.content = '# My First Wiki Content' - resource.message = 'Update home' end end def initialize @file_name = 'Home.md' - @file_content = '# Welcome to My Wiki' - @commit_message = 'Updating Home Page' + @file_content = 'This line was created using git push' + @commit_message = 'Updating using git push' @branch_name = 'master' @new_branch = false end @@ -28,9 +28,12 @@ module QA @repository_ssh_uri ||= wiki.repository_ssh_location.uri end - def fabricate! - super - wiki.visit! + def web_url + # TODO + # workaround + # i.e. This replaces the last occurence of the string (case sensitive) + # and attaches everything before to the new substring + repository_http_uri.to_s.gsub(/(.*)\b\.wiki\.git\b/i, "\\1/-/wikis/#{@file_name.gsub('.md', '')}") end end end diff --git a/qa/qa/resource/sandbox.rb b/qa/qa/resource/sandbox.rb index 7b427af6b74..032ff65c58b 100644 --- a/qa/qa/resource/sandbox.rb +++ b/qa/qa/resource/sandbox.rb @@ -13,6 +13,7 @@ module QA attribute :id attribute :runners_token + attribute :name def initialize @path = Runtime::Namespace.sandbox_name diff --git a/qa/qa/resource/ssh_key.rb b/qa/qa/resource/ssh_key.rb index b948bf3969b..317d70ef2c3 100644 --- a/qa/qa/resource/ssh_key.rb +++ b/qa/qa/resource/ssh_key.rb @@ -6,6 +6,7 @@ module QA extend Forwardable attr_reader :title + attr_accessor :expires_at attribute :id @@ -53,13 +54,27 @@ module QA def api_post_body { title: title, - key: public_key + key: public_key, + expires_at: expires_at } end def api_delete_path "/user/keys/#{id}" end + + def replicated? + api_client = Runtime::API::Client.new(:geo_secondary) + + QA::Runtime::Logger.debug('Checking for SSH key replication') + + Support::Retrier.retry_until(max_duration: QA::EE::Runtime::Geo.max_db_replication_time, sleep_interval: 3) do + response = get Runtime::API::Request.new(api_client, api_get_path).url + + response.code == QA::Support::Api::HTTP_STATUS_OK && + parse_body(response)[:title].include?(title) + end + end end end end diff --git a/qa/qa/resource/wiki.rb b/qa/qa/resource/wiki.rb deleted file mode 100644 index 45d5da9346d..00000000000 --- a/qa/qa/resource/wiki.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -module QA - module Resource - class Wiki < Base - attr_accessor :title, :content, :message - - attribute :project do - Project.fabricate! do |resource| - resource.name = 'project-for-wikis' - resource.description = 'project for adding wikis' - end - end - - attribute :repository_http_location do - Page::Project::Wiki::Show.perform(&:click_clone_repository) - - Page::Project::Wiki::GitAccess.perform do |git_access| - git_access.choose_repository_clone_http - git_access.repository_location - end - end - - attribute :repository_ssh_location do - Page::Project::Wiki::Show.perform(&:click_clone_repository) - - Page::Project::Wiki::GitAccess.perform do |git_access| - git_access.choose_repository_clone_ssh - git_access.repository_location - end - end - - def fabricate! - project.visit! - - Page::Project::Menu.perform { |menu_side| menu_side.click_wiki } - - Page::Project::Wiki::New.perform do |wiki_new| - wiki_new.click_create_your_first_page_button - wiki_new.set_title(@title) - wiki_new.set_content(@content) - wiki_new.set_message(@message) - wiki_new.create_new_page - end - end - end - end -end diff --git a/qa/qa/resource/wiki/project_page.rb b/qa/qa/resource/wiki/project_page.rb new file mode 100644 index 00000000000..5d0a0a37765 --- /dev/null +++ b/qa/qa/resource/wiki/project_page.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +module QA + module Resource + module Wiki + class ProjectPage < Base + attribute :title + attribute :content + attribute :slug + attribute :format + + attribute :project do + Project.fabricate_via_api! do |project| + project.name = 'wiki_testing' + project.description = 'project for testing wikis' + end + end + + attribute :repository_http_location do + switching_to_wiki_url project.repository_http_location.git_uri + end + + attribute :repository_ssh_location do + switching_to_wiki_url project.repository_ssh_location.git_uri + end + + def initialize + @title = 'Home' + @content = 'This wiki page is created by the API' + end + + def resource_web_url(resource) + super + rescue ResourceURLMissingError + # TODO + # workaround + project.web_url.concat("/-/wikis/#{slug}") + end + + def api_get_path + "/projects/#{project.id}/wikis/#{slug}" + end + + def api_post_path + "/projects/#{project.id}/wikis" + end + + def api_post_body + { + id: project.id, + content: content, + title: title + } + end + + private + + def switching_to_wiki_url(url) + # TODO + # workaround + # i.e. This replaces the last occurence of the string (case sensitive) + # and attaches everything before to the new substring + Git::Location.new(url.to_s.gsub(/(.*)\bgit\b/i, '\1wiki.git')) + end + end + end + end +end |