summaryrefslogtreecommitdiff
path: root/qa/qa/resource
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/resource')
-rw-r--r--qa/qa/resource/events/project.rb2
-rw-r--r--qa/qa/resource/file.rb2
-rw-r--r--qa/qa/resource/group.rb1
-rw-r--r--qa/qa/resource/merge_request.rb13
-rw-r--r--qa/qa/resource/merge_request_from_fork.rb4
-rw-r--r--qa/qa/resource/pipeline.rb5
-rw-r--r--qa/qa/resource/project.rb9
-rw-r--r--qa/qa/resource/protected_branch.rb76
-rw-r--r--qa/qa/resource/repository/commit.rb15
-rw-r--r--qa/qa/resource/repository/project_push.rb3
-rw-r--r--qa/qa/resource/repository/push.rb7
-rw-r--r--qa/qa/resource/repository/wiki_push.rb5
-rw-r--r--qa/qa/resource/sandbox.rb14
-rw-r--r--qa/qa/resource/user.rb10
14 files changed, 125 insertions, 41 deletions
diff --git a/qa/qa/resource/events/project.rb b/qa/qa/resource/events/project.rb
index 8c97f66c663..0348f2f05f5 100644
--- a/qa/qa/resource/events/project.rb
+++ b/qa/qa/resource/events/project.rb
@@ -20,7 +20,7 @@ module QA
end
end
- def wait_for_push_new_branch(branch_name = "master")
+ def wait_for_push_new_branch(branch_name = self.default_branch)
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push_new_branch with branch_name "#{branch_name}"])
wait_for_event do
events(action: 'pushed').any? { |event| event.dig(:push_data, :ref) == branch_name }
diff --git a/qa/qa/resource/file.rb b/qa/qa/resource/file.rb
index 0d2bf9890ea..4ca180373f6 100644
--- a/qa/qa/resource/file.rb
+++ b/qa/qa/resource/file.rb
@@ -30,7 +30,7 @@ module QA
end
def branch
- @branch ||= "master"
+ @branch ||= project.default_branch
end
def fabricate!
diff --git a/qa/qa/resource/group.rb b/qa/qa/resource/group.rb
index 2e29ec9a6a7..135c3dea628 100644
--- a/qa/qa/resource/group.rb
+++ b/qa/qa/resource/group.rb
@@ -36,7 +36,6 @@ module QA
Page::Group::New.perform do |group_new|
group_new.set_path(path)
- group_new.set_description(description)
group_new.set_visibility('Public')
group_new.create
end
diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb
index dca8fb6dc6b..ecf25b797a8 100644
--- a/qa/qa/resource/merge_request.rb
+++ b/qa/qa/resource/merge_request.rb
@@ -34,7 +34,7 @@ module QA
attribute :target do
Repository::ProjectPush.fabricate! do |resource|
resource.project = project
- resource.branch_name = 'master'
+ resource.branch_name = project.default_branch
resource.new_branch = @target_new_branch
resource.remote_branch = target_branch
end
@@ -56,7 +56,6 @@ module QA
@title = 'QA test - merge request'
@description = 'This is a test merge request'
@source_branch = "qa-test-feature-#{SecureRandom.hex(8)}"
- @target_branch = "master"
@assignee = nil
@milestone = nil
@labels = []
@@ -68,7 +67,7 @@ module QA
end
def fabricate!
- populate(:target, :source)
+ populate_target_and_source_if_required
project.visit!
Page::Project::Show.perform(&:new_merge_request)
@@ -89,7 +88,7 @@ module QA
def fabricate_via_api!
resource_web_url(api_get)
rescue ResourceNotFoundError
- populate(:target, :source) unless @no_preparation
+ populate_target_and_source_if_required
super
end
@@ -144,6 +143,12 @@ module QA
super(api_resource)
end
+
+ def populate_target_and_source_if_required
+ @target_branch ||= project.default_branch
+
+ populate(:target, :source) unless @no_preparation
+ end
end
end
end
diff --git a/qa/qa/resource/merge_request_from_fork.rb b/qa/qa/resource/merge_request_from_fork.rb
index d9c86b3b527..b0367df64ed 100644
--- a/qa/qa/resource/merge_request_from_fork.rb
+++ b/qa/qa/resource/merge_request_from_fork.rb
@@ -28,6 +28,10 @@ module QA
Page::Project::Show.perform(&:new_merge_request)
Page::MergeRequest::New.perform(&:create_merge_request)
end
+
+ def fabricate_via_api!
+ raise NotImplementedError
+ end
end
end
end
diff --git a/qa/qa/resource/pipeline.rb b/qa/qa/resource/pipeline.rb
index a115de3e825..907a6cb8558 100644
--- a/qa/qa/resource/pipeline.rb
+++ b/qa/qa/resource/pipeline.rb
@@ -22,7 +22,6 @@ module QA
attribute :variables
def initialize
- @ref = 'master'
@variables = []
end
@@ -34,6 +33,10 @@ module QA
Page::Project::Pipeline::New.perform(&:click_run_pipeline_button)
end
+ def ref
+ project.default_branch
+ end
+
def api_get_path
"/projects/#{project.id}/pipelines/#{id}"
end
diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb
index 163c0b40bb5..a92f7912b9e 100644
--- a/qa/qa/resource/project.rb
+++ b/qa/qa/resource/project.rb
@@ -15,7 +15,6 @@ module QA
attr_writer :github_personal_access_token
attr_writer :github_repository_path
- attribute :default_branch
attribute :id
attribute :name
attribute :add_name_uuid
@@ -26,6 +25,10 @@ module QA
attribute :template_name
attribute :import
+ attribute :default_branch do
+ api_response[:default_branch] || Runtime::Env.default_branch
+ end
+
attribute :group do
Group.fabricate!
end
@@ -200,6 +203,10 @@ module QA
post_body
end
+ def api_delete_path
+ "/projects/#{id}"
+ end
+
def change_repository_storage(new_storage)
put_body = { repository_storage: new_storage }
response = put Runtime::API::Request.new(api_client, api_put_path).url, put_body
diff --git a/qa/qa/resource/protected_branch.rb b/qa/qa/resource/protected_branch.rb
index 9b728fc4c24..51ea9d1c5b9 100644
--- a/qa/qa/resource/protected_branch.rb
+++ b/qa/qa/resource/protected_branch.rb
@@ -8,7 +8,6 @@ module QA
attr_accessor :branch_name,
:allowed_to_push,
:allowed_to_merge,
- :protected,
:new_branch,
:require_code_owner_approval
@@ -20,13 +19,14 @@ module QA
end
attribute :branch do
- Repository::ProjectPush.fabricate! do |project_push|
- project_push.project = project
- project_push.file_name = "new_file-#{SecureRandom.hex(8)}.md"
- project_push.commit_message = 'Add new file'
- project_push.branch_name = branch_name
- project_push.new_branch = true
- project_push.remote_branch = branch_name
+ Resource::Repository::Commit.fabricate_via_api! do |commit|
+ commit.project = project
+ commit.branch = branch_name
+ commit.start_branch = 'master'
+ commit.commit_message = 'Add new file'
+ commit.add_files([
+ { file_path: "new_file-#{SecureRandom.hex(8)}.md", content: 'new file' }
+ ])
end
end
@@ -39,16 +39,11 @@ module QA
@allowed_to_merge = {
roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS
}
- @protected = false
- @require_code_owner_approval = true
+ @require_code_owner_approval = false
end
def fabricate!
- if new_branch
- populate(:branch)
-
- project.wait_for_push_new_branch branch_name
- end
+ populate_new_branch_if_required
project.visit!
Page::Project::Menu.perform(&:go_to_repository_settings)
@@ -67,6 +62,12 @@ module QA
end
end
+ def fabricate_via_api!
+ populate_new_branch_if_required
+
+ super
+ end
+
def self.unprotect_via_api!(&block)
self.remove_via_api!(&block)
end
@@ -79,10 +80,49 @@ module QA
"/projects/#{project.id}/protected_branches/#{branch_name}"
end
+ def api_post_path
+ "/projects/#{project.id}/protected_branches"
+ end
+
+ def api_post_body
+ {
+ name: branch_name,
+ code_owner_approval_required: require_code_owner_approval
+ }
+ .merge(allowed_to_push_hash)
+ .merge(allowed_to_merge_hash)
+ end
+
+ def allowed_to_push_hash
+ allowed = {}
+ allowed.merge({ push_access_level: allowed_to_push[:roles][:access_level] }) if allowed_to_push.key?(:roles)
+ end
+
+ def allowed_to_merge_hash
+ allowed = {}
+ allowed.merge({ merge_access_level: allowed_to_merge[:roles][:access_level] }) if allowed_to_merge.key?(:roles)
+ end
+
+ def resource_web_url(resource)
+ super
+ rescue ResourceURLMissingError
+ # this particular resource does not expose a web_url property
+ end
+
class Roles
- NO_ONE = 'No one'
- DEVS_AND_MAINTAINERS = 'Developers + Maintainers'
- MAINTAINERS = 'Maintainers'
+ NO_ONE = { description: 'No one', access_level: 0 }.freeze
+ DEVS_AND_MAINTAINERS = { description: 'Developers + Maintainers', access_level: 30 }.freeze
+ MAINTAINERS = { description: 'Maintainers', access_level: 40 }.freeze
+ end
+
+ private
+
+ def populate_new_branch_if_required
+ return unless new_branch
+
+ populate(:branch)
+
+ project.wait_for_push_new_branch(branch_name)
end
end
end
diff --git a/qa/qa/resource/repository/commit.rb b/qa/qa/resource/repository/commit.rb
index d15210aa736..f5dba164de6 100644
--- a/qa/qa/resource/repository/commit.rb
+++ b/qa/qa/resource/repository/commit.rb
@@ -9,7 +9,8 @@ module QA
:branch,
:commit_message,
:file_path,
- :sha
+ :sha,
+ :start_branch
attribute :short_id
@@ -80,12 +81,12 @@ module QA
def api_post_body
{
- branch: @branch || "master",
+ branch: @branch || project.default_branch,
author_email: @author_email || Runtime::User.default_email,
author_name: @author_name || Runtime::User.username,
commit_message: commit_message,
actions: actions
- }
+ }.merge(new_branch)
end
def actions
@@ -104,6 +105,14 @@ module QA
raise ArgumentError, "Please provide an array of hashes e.g.: [{file_path: 'file1', content: 'foo'}]"
end
end
+
+ def new_branch
+ return {} unless start_branch
+
+ {
+ start_branch: start_branch
+ }
+ end
end
end
end
diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb
index c46921ad0c7..ef4873e9483 100644
--- a/qa/qa/resource/repository/project_push.rb
+++ b/qa/qa/resource/repository/project_push.rb
@@ -23,7 +23,6 @@ module QA
@file_name = "file-#{SecureRandom.hex(8)}.txt"
@file_content = '# This is test project'
@commit_message = "This is a test commit"
- @branch_name = 'master'
@new_branch = true
@project_name = 'project-with-code'
@wait_for_push = true
@@ -39,6 +38,8 @@ module QA
end
def fabricate!
+ @branch_name ||= project.default_branch
+
super
project.wait_for_push @commit_message if @wait_for_push
end
diff --git a/qa/qa/resource/repository/push.rb b/qa/qa/resource/repository/push.rb
index 5266f8b9bea..f5b6040d927 100644
--- a/qa/qa/resource/repository/push.rb
+++ b/qa/qa/resource/repository/push.rb
@@ -17,7 +17,6 @@ module QA
@file_name = "file-#{SecureRandom.hex(8)}.txt"
@file_content = '# This is test file'
@commit_message = "This is a test commit"
- @branch_name = 'master'
@new_branch = true
@repository_http_uri = ""
@ssh_key = nil
@@ -78,6 +77,8 @@ module QA
@output += repository.clone
repository.configure_identity(name, email)
+ @branch_name ||= default_branch(repository)
+
@output += repository.checkout(branch_name, new_branch: new_branch)
if @tag_name
@@ -105,6 +106,10 @@ module QA
private
+ def default_branch(repository)
+ repository.remote_branches.last || Runtime::Env.default_branch
+ end
+
def commit_to(repository)
@gpg_key_id.nil? ? repository.commit(@commit_message) : repository.commit_with_gpg(@commit_message)
end
diff --git a/qa/qa/resource/repository/wiki_push.rb b/qa/qa/resource/repository/wiki_push.rb
index edf76c7cd78..f188e52c969 100644
--- a/qa/qa/resource/repository/wiki_push.rb
+++ b/qa/qa/resource/repository/wiki_push.rb
@@ -12,11 +12,14 @@ module QA
end
end
+ def branch_name
+ @branch_name ||= wiki.project.default_branch
+ end
+
def initialize
@file_name = 'Home.md'
@file_content = 'This line was created using git push'
@commit_message = 'Updating using git push'
- @branch_name = 'master'
@new_branch = false
end
diff --git a/qa/qa/resource/sandbox.rb b/qa/qa/resource/sandbox.rb
index b351d92092f..ae183d55d89 100644
--- a/qa/qa/resource/sandbox.rb
+++ b/qa/qa/resource/sandbox.rb
@@ -31,7 +31,6 @@ module QA
Page::Group::New.perform do |group|
group.set_path(path)
- group.set_description('GitLab QA Sandbox Group')
group.set_visibility('Public')
group.create
end
@@ -76,6 +75,19 @@ module QA
visibility: 'public'
}
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
+
+ unless response.code == HTTP_STATUS_OK
+ raise ResourceUpdateFailedError, "Could not update #{group_setting} to #{value}. Request returned (#{response.code}): `#{response}`."
+ end
+ end
end
end
end
diff --git a/qa/qa/resource/user.rb b/qa/qa/resource/user.rb
index ca30ff12480..f95a68918dc 100644
--- a/qa/qa/resource/user.rb
+++ b/qa/qa/resource/user.rb
@@ -7,7 +7,7 @@ module QA
class User < Base
attr_reader :unique_id
attr_writer :username, :password
- attr_accessor :admin, :provider, :extern_uid
+ attr_accessor :admin, :provider, :extern_uid, :expect_fabrication_success
attribute :id
attribute :name
@@ -18,6 +18,7 @@ module QA
def initialize
@admin = false
@unique_id = SecureRandom.hex(8)
+ @expect_fabrication_success = true
end
def admin?
@@ -74,12 +75,7 @@ module QA
login.sign_in_using_credentials(user: self)
end
else
- Page::Main::Login.perform do |login|
- login.switch_to_register_page
- end
- Page::Main::SignUp.perform do |signup|
- signup.sign_up!(self)
- end
+ Flow::SignUp.sign_up!(self)
end
end