Commit e6e68627 authored by Dan Davison's avatar Dan Davison

Merge branch 'ml-qa-use-project-default-branch' into 'master'

Use project default branch in QA tests

See merge request gitlab-org/gitlab!48967
parents ea68aad4 81412946
......@@ -14,7 +14,7 @@ module QA
include Support::Run
attr_writer :use_lfs, :gpg_key_id
attr_accessor :env_vars
attr_accessor :env_vars, :default_branch
InvalidCredentialsError = Class.new(RuntimeError)
......@@ -25,6 +25,7 @@ module QA
self.env_vars = [%Q{HOME="#{tmp_home_dir}"}]
@use_lfs = false
@gpg_key_id = nil
@default_branch = Runtime::Env.default_branch
end
def self.perform(*args)
......@@ -123,7 +124,7 @@ module QA
run_git("git rev-parse --abbrev-ref HEAD").to_s
end
def push_changes(branch = 'master', push_options: nil)
def push_changes(branch = @default_branch, push_options: nil)
cmd = ['git push']
cmd << push_options_hash_to_string(push_options)
cmd << uri
......@@ -209,6 +210,13 @@ module QA
File.delete(netrc_file_path) if File.exist?(netrc_file_path)
end
def remote_branches
# This gets the remote branch names
# When executed on a fresh repo it returns the default branch name
run_git('git --no-pager branch --list --remotes --format="%(refname:lstrip=3)"').to_s.split("\n")
end
private
attr_reader :uri, :username, :password, :ssh, :use_lfs
......
......@@ -70,7 +70,7 @@ module QA
end
end
def duplicate_dashboard(save_as = 'test_duplication.yml', commit_option = 'Commit to master branch')
def duplicate_dashboard(save_as = 'test_duplication.yml', commit_option = 'Commit to default branch')
click_element :actions_menu_dropdown
click_on 'Duplicate current dashboard'
fill_element :duplicate_dashboard_filename_field, "#{SecureRandom.hex(8)}-#{save_as}"
......
......@@ -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 }
......
......@@ -30,7 +30,7 @@ module QA
end
def branch
@branch ||= "master"
@branch ||= project.default_branch
end
def fabricate!
......
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -81,7 +81,7 @@ 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,
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -63,7 +63,7 @@ module QA
end
def pipeline_from_project_name
ci_project_name.to_s.start_with?('gitlab-qa') ? 'master' : ci_project_name
ci_project_name.to_s.start_with?('gitlab-qa') ? Runtime::Env.default_branch : ci_project_name
end
def additional_repository_storage
......@@ -102,6 +102,10 @@ module QA
enabled?(ENV['QA_DEBUG'], default: false)
end
def default_branch
ENV['QA_DEFAULT_BRANCH'] || 'master'
end
def log_destination
ENV['QA_LOG_PATH'] || $stdout
end
......
......@@ -37,7 +37,7 @@ module QA
Support::Waiter.wait_until(retry_on_exception: true, sleep_interval: 5) do
Resource::Repository::Commit.fabricate_via_api! do |commits|
commits.project = project
commits.sha = 'master'
commits.sha = project.default_branch
end
end
......
......@@ -21,27 +21,29 @@ module QA
a_hash_including(name: project_name, path: project_name)
)
default_branch = json_body[:default_branch].to_s.empty? ? Runtime::Env.default_branch : json_body[:default_branch]
create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md")
post create_file_request.url, branch: 'master', content: 'Hello world', commit_message: 'Add README.md'
post create_file_request.url, branch: default_branch, content: 'Hello world', commit_message: 'Add README.md'
expect_status(201)
expect(json_body).to match(
a_hash_including(branch: 'master', file_path: 'README.md')
a_hash_including(branch: default_branch, file_path: 'README.md')
)
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", ref: 'master')
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", ref: default_branch)
get get_file_request.url
expect_status(200)
expect(json_body).to match(
a_hash_including(
ref: 'master',
ref: default_branch,
file_path: 'README.md', file_name: 'README.md',
encoding: 'base64', content: 'SGVsbG8gd29ybGQ='
)
)
delete_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", branch: 'master', commit_message: 'Remove README.md')
delete_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", branch: default_branch, commit_message: 'Remove README.md')
delete delete_file_request.url
expect_status(204)
......@@ -80,10 +82,12 @@ module QA
create_project_request = Runtime::API::Request.new(@api_client, '/projects')
post create_project_request.url, path: project_name, name: project_name
default_branch = json_body[:default_branch].to_s.empty? ? Runtime::Env.default_branch : json_body[:default_branch]
create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg")
post create_file_request.url, branch: 'master', content: svg_file, commit_message: 'Add test.svg'
post create_file_request.url, branch: default_branch, content: svg_file, commit_message: 'Add test.svg'
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg/raw", ref: 'master')
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg/raw", ref: default_branch)
3.times do
response = get get_file_request.url
......
......@@ -42,7 +42,7 @@ module QA
end
let!(:pipeline_id) do
pipeline_create_request = Runtime::API::Request.new(api_client, "/projects/#{project.id}/pipeline?ref=master")
pipeline_create_request = Runtime::API::Request.new(api_client, "/projects/#{project.id}/pipeline?ref=#{project.default_branch}")
JSON.parse(post(pipeline_create_request.url, nil))['id']
end
......
......@@ -6,17 +6,18 @@ module QA
it 'user creates an event in the activity page upon Git push', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/407' do
Flow::Login.sign_in
Resource::Repository::ProjectPush.fabricate! do |push|
project = Resource::Repository::ProjectPush.fabricate! do |push|
push.file_name = 'README.md'
push.file_content = '# This is a test project'
push.commit_message = 'Add README.md'
end.project.visit!
end.project
project.visit!
Page::Project::Menu.perform(&:click_activity)
Page::Project::Activity.perform do |activity|
activity.click_push_events
expect(activity).to have_content('pushed new branch master')
expect(activity).to have_content("pushed new branch #{project.default_branch}")
end
end
end
......
......@@ -36,7 +36,6 @@ module QA
QA::Support::Retrier.retry_on_exception do
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project
push.branch_name = 'master'
push.new_branch = false
push.file_name = "file_#{SecureRandom.hex(4)}.txt"
end
......
......@@ -80,7 +80,6 @@ module QA
def push_commit(commit_message)
Resource::Repository::ProjectPush.fabricate! do |push|
push.branch_name = 'master'
push.commit_message = commit_message
push.file_content = commit_message
push.project = project
......@@ -101,7 +100,7 @@ module QA
end
def master_branch_exists?
project.repository_branches.map { |item| item[:name] }.include?("master")
project.repository_branches.map { |item| item[:name] }.include?(project.default_branch)
end
end
end
......
......@@ -27,7 +27,6 @@ module QA
push.project = project
push.file_name = "other.txt"
push.file_content = "New file added!"
push.branch_name = "master"
push.new_branch = false
end
......
......@@ -37,8 +37,8 @@ module QA
mr_page.click_diffs_tab
mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)')
expect(mr_page.version_dropdown_content).not_to include('master (base)')
expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (HEAD)")
expect(mr_page.version_dropdown_content).not_to include("#{project.default_branch} (base)")
expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).not_to have_file(new_file_name)
end
......@@ -62,8 +62,8 @@ module QA
mr_page.click_diffs_tab
mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)')
expect(mr_page.version_dropdown_content).to include('master (base)')
expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (HEAD)")
expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (base)")
expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).to have_file(new_file_name)
end
......
......@@ -3,7 +3,7 @@
module QA
RSpec.describe 'Create' do
describe 'Create, list, and delete branches via web' do
master_branch = 'master'
master_branch = nil
second_branch = 'second-branch'
third_branch = 'third-branch'
file_1_master = 'file.txt'
......@@ -21,12 +21,16 @@ module QA
project = Resource::Project.fabricate_via_api! do |proj|
proj.name = 'project-qa-test'
proj.description = 'project for qa test'
proj.initialize_with_readme = true
end
master_branch = project.default_branch
Git::Repository.perform do |repository|
repository.uri = project.repository_http_location.uri
repository.use_default_credentials
repository.try_add_credentials_to_netrc
repository.default_branch = master_branch
repository.act do
clone
......
......@@ -7,7 +7,6 @@ module QA
let(:changed_content) { 'changes' }
let(:commit_message) { 'Changes to snippets' }
let(:added_content) { 'updated ' }
let(:branch_name) { 'master' }
let(:snippet) do
Resource::Snippet.fabricate! do |snippet|
......@@ -41,7 +40,7 @@ module QA
end
it 'clones, pushes, and pulls a snippet over HTTP, edits via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/826' do
Resource::Repository::Push.fabricate! do |push|
push = Resource::Repository::Push.fabricate! do |push|
push.repository_http_uri = repository_uri_http
push.file_name = new_file
push.file_content = changed_content
......@@ -61,7 +60,7 @@ module QA
Git::Repository.perform do |repository|
repository.init_repository
repository.pull(repository_uri_http, branch_name)
repository.pull(repository_uri_http, push.branch_name)
expect(repository.commits.size).to eq(3)
expect(repository.commits.first).to include('Update snippet')
......@@ -70,7 +69,7 @@ module QA
end
it 'clones, pushes, and pulls a snippet over SSH, deletes via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/825' do
Resource::Repository::Push.fabricate! do |push|
push = Resource::Repository::Push.fabricate! do |push|
push.repository_ssh_uri = repository_uri_ssh
push.ssh_key = ssh_key
push.file_name = new_file
......@@ -90,7 +89,7 @@ module QA
repository.use_ssh_key(ssh_key)
repository.init_repository
expect { repository.pull(repository_uri_ssh, branch_name) }
expect { repository.pull(repository_uri_ssh, push.branch_name) }
.to raise_error(QA::Support::Run::CommandError, /fatal: Could not read from remote repository\./)
end
end
......
......@@ -7,7 +7,7 @@ module QA
let(:changed_content) { 'changes' }
let(:commit_message) { 'Changes to snippets' }
let(:added_content) { 'updated ' }
let(:branch_name) { 'master' }
let(:branch_name) { snippet.project.default_branch }
let(:snippet) do
Resource::ProjectSnippet.fabricate! do |snippet|
......
......@@ -54,7 +54,7 @@ module QA
script:
- 'gradle publish'
only:
- master
- "#{project.default_branch}"
tags:
- "runner-for-#{project.name}"
YAML
......
......@@ -51,7 +51,7 @@ module QA
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab
only:
- master
- "#{project.default_branch}"
tags:
- "runner-for-#{project.name}"
YAML
......
......@@ -24,13 +24,7 @@ module QA
file_name: '.gitlab-ci.yml',
template: 'custom_gitlab-ci',
file_path: 'gitlab-ci/custom_gitlab-ci.yml',
content:
<<~CI
job:
script: echo "Skipped"
except:
- master
CI
content: 'gitlab-ci.yml template test'
},
{
file_name: 'LICENSE',
......
......@@ -26,7 +26,7 @@ module QA
end
it 'merge request assigns code owners as approvers', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/605' do
# Commit CODEOWNERS to master
# Commit CODEOWNERS to default branch
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add CODEOWNERS and test files'
......@@ -69,7 +69,7 @@ module QA
end.visit!
# Check that the merge request assigns the original code owner as an
# approver (because the current CODEOWNERS file in the master branch
# approver (because the current CODEOWNERS file in the default branch
# doesn't have the new owner yet)
Page::MergeRequest::Show.perform do |show|
show.edit!
......
......@@ -3,55 +3,57 @@
module QA
RSpec.describe 'Create' do
describe 'File Locking' do
before do
Flow::Login.sign_in
let(:user_one) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1) }
let(:user_two) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2) }
@user_one = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
@user_two = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2)
@project = Resource::Project.fabricate_via_api! do |project|
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'file_locking'
end
end
before do
Flow::Login.sign_in
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project
push.project = project
push.file_name = 'file'
push.file_content = SecureRandom.hex(100000)
end
add_to_project user: @user_one
add_to_project user: @user_two
add_to_project user: user_one
add_to_project user: user_two
Resource::ProtectedBranch.unprotect_via_api! do |branch|
branch.project = @project
branch.branch_name = 'master'
branch.project = project
branch.branch_name = project.default_branch
end
end
it 'locks a directory and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/557' do
push branch: 'master', file: 'directory/file', as_user: @user_one
push branch: project.default_branch, file: 'directory/file', as_user: user_one
sign_out_and_sign_in_as user: @user_one
sign_out_and_sign_in_as user: user_one
go_to_directory
click_lock
expect_error_on_push for_file: 'directory/file', as_user: @user_two
expect_no_error_on_push for_file: 'directory/file', as_user: @user_one
expect_error_on_push for_file: 'directory/file', as_user: user_two
expect_no_error_on_push for_file: 'directory/file', as_user: user_one
end
it 'locks a file and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/558' do
sign_out_and_sign_in_as user: @user_one
sign_out_and_sign_in_as user: user_one
go_to_file
click_lock
expect_error_on_push as_user: @user_two
expect_no_error_on_push as_user: @user_one
expect_error_on_push as_user: user_two
expect_no_error_on_push as_user: user_one
end
it 'checks file locked by other user to be disabled', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/556' do
go_to_file
click_lock
sign_out_and_sign_in_as user: @user_one
sign_out_and_sign_in_as user: user_one
go_to_file
Page::File::Show.perform do |show|
......@@ -60,28 +62,28 @@ module QA
end
it 'creates a merge request and fails to merge', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/40125', type: :bug }, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/559' do
push branch: 'test', as_user: @user_one
push branch: 'test', as_user: user_one
merge_request = Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project
merge_request.project = project
merge_request.source_branch = 'test'
merge_request.target_branch = 'master'
merge_request.target_branch = project.default_branch
merge_request.no_preparation = true
end
go_to_file
click_lock
sign_out_and_sign_in_as user: @user_one
sign_out_and_sign_in_as user: user_one
try_to_merge merge_request: merge_request
Page::MergeRequest::Show.perform(&:wait_for_merge_request_error_message)
expect(page).to have_text("locked by #{admin_username}")
end
it 'locks a file and unlocks in list', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/555' do
sign_out_and_sign_in_as user: @user_one
sign_out_and_sign_in_as user: user_one
go_to_file
click_lock
@project.visit!
project.visit!
Page::Project::Menu.perform(&:go_to_repository_locked_files)
EE::Page::Project::PathLocks::Index.perform do |list|
......@@ -89,7 +91,7 @@ module QA
list.unlock_file 'file'
end
expect_no_error_on_push as_user: @user_two
expect_no_error_on_push as_user: user_two
end
def try_to_merge(merge_request:)
......@@ -106,14 +108,14 @@ module QA
end
def go_to_file
@project.visit!
project.visit!
Page::Project::Show.perform do |project_page|
project_page.click_file 'file'
end
end
def go_to_directory
@project.visit!
project.visit!
Page::Project::Show.perform do |project_page|
project_page.click_file 'directory'
end
......@@ -126,15 +128,15 @@ module QA
def add_to_project(user:)
Resource::ProjectMember.fabricate_via_api! do |member|
member.user = user
member.project = @project
member.project = project
member.access_level = member.level[:developer]
end
end
def push(branch: 'master', file: 'file', as_user:)
def push(branch: project.default_branch, file: 'file', as_user:)
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project
push.new_branch = false unless branch != 'master'
push.project = project
push.new_branch = false unless branch != project.default_branch
push.file_name = file
push.file_content = SecureRandom.hex(100000)
push.user = as_user
......@@ -143,12 +145,12 @@ module QA
end
def expect_error_on_push(for_file: 'file', as_user:)
expect { push branch: 'master', file: for_file, as_user: as_user }.to raise_error(
expect { push branch: project.default_branch, file: for_file, as_user: as_user }.to raise_error(
QA::Support::Run::CommandError)
end
def expect_no_error_on_push(for_file: 'file', as_user:)
expect { push branch: 'master', file: for_file, as_user: as_user }.not_to raise_error
expect { push branch: project.default_branch, file: for_file, as_user: as_user }.not_to raise_error
end
def admin_username
......
......@@ -10,7 +10,7 @@ module QA
@file_name_limitation = 'denied_file'
@file_size_limitation = 1
@authors_email_limitation = %{(#{Regexp.escape(@creator.email)}|#{@root.email})}
@branch_name_limitation = 'master'
@branch_name_limitation = @project.default_branch
@needed_phrase_limitation = 'allowed commit'
@deny_message_phrase_limitation = 'denied commit'
......@@ -89,7 +89,7 @@ module QA
it 'restricts removal of tag', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/650' do
tag = Resource::Tag.fabricate_via_api! do |tag|
tag.project = @project
tag.ref = 'master'
tag.ref = @project.default_branch
tag.name = "test_tag_#{SecureRandom.hex(8)}"
end
......@@ -173,7 +173,7 @@ module QA
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project
push.commit_message = commit_message
push.new_branch = branch != 'master'
push.new_branch = branch != @project.default_branch
push.branch_name = branch
push.user = user if user != @root
push.files = file if tag.nil?
......@@ -182,13 +182,13 @@ module QA
end
end
def expect_no_error_on_push(commit_message: 'allowed commit', branch: 'master', file:, user: @creator, tag: nil, gpg: nil)
def expect_no_error_on_push(commit_message: 'allowed commit', branch: @project.default_branch, file:, user: @creator, tag: nil, gpg: nil)
expect do
push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg
end.not_to raise_error
end
def expect_error_on_push(commit_message: 'allowed commit', branch: 'master', file:, user: @creator, tag: nil, gpg: nil, error: nil)
def expect_error_on_push(commit_message: 'allowed commit', branch: @project.default_branch, file:, user: @creator, tag: nil, gpg: nil, error: nil)
expect do
push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg
end.to raise_error(QA::Support::Run::CommandError, /#{error}/)
......
......@@ -63,7 +63,7 @@ module QA
it 'creates a pipeline with merged results', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do
branch_name = "merged-results-#{SecureRandom.hex(8)}"
# Create a branch that will be merged into master
# Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project
project_push.new_branch = true
......@@ -98,7 +98,7 @@ module QA
it 'merges via a merge train', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/561' do
branch_name = "merge-train-#{SecureRandom.hex(8)}"
# Create a branch that will be merged into master
# Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project
project_push.new_branch = true
......
......@@ -46,9 +46,9 @@ module QA
merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project
mr.source_branch = 'secure-mr'
mr.target_branch = 'master'
mr.target_branch = @project.default_branch
mr.source = @source
mr.target = 'master'
mr.target = @project.default_branch
mr.target_new_branch = false
end
......
......@@ -41,8 +41,8 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project
mr.source_branch = 'license-management-mr'
mr.target_branch = 'master'
mr.target = 'master'
mr.target_branch = @project.default_branch
mr.target = @project.default_branch
mr.file_name = 'gl-license-scanning-report.json'
mr.file_content =
<<~FILE_UPDATE
......
......@@ -37,9 +37,9 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project
mr.source_branch = 'secure-mr'
mr.target_branch = 'master'
mr.target_branch = @project.default_branch
mr.source = @source
mr.target = 'master'
mr.target = @project.default_branch
mr.target_new_branch = false
end
......
......@@ -45,9 +45,9 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project
mr.source_branch = 'secure-mr'
mr.target_branch = 'master'
mr.target_branch = @project.default_branch
mr.source = @source
mr.target = 'master'
mr.target = @project.default_branch
mr.target_new_branch = false
end
......
......@@ -95,20 +95,20 @@ module QA
def create_many_merge_requests
30.times do |i|
create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "branch#{i}", "master", "MR#{i}")
create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "branch#{i}", Runtime::Env.default_branch, "MR#{i}")
end
@urls[:mr_list_page] = @urls[:project_page] + "/merge_requests"
STDOUT.puts "Created many MRs: #{@urls[:mr_list_page]}"
end
def create_many_new_files
create_a_new_file_api_req("hello.txt", "master", "#{@group_name}%2F#{@project_name}", "hello", "my new content")
create_a_new_file_api_req("hello.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "hello", "my new content")
30.times do |i|
create_a_new_file_api_req("hello#{i}.txt", "master", "#{@group_name}%2F#{@project_name}", "hello", "my new content")
create_a_new_file_api_req("hello#{i}.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "hello", "my new content")
create_a_new_file_api_req("hello#{i}.txt", "branch#{i}", "#{@group_name}%2F#{@project_name}", "hello", "my new content")
end
@urls[:files_page] = @urls[:project_page] + "/tree/master"
@urls[:files_page] = @urls[:project_page] + "/tree/#{Runtime::Env.default_branch}"
STDOUT.puts "Added many new files: #{@urls[:files_page]}"
end
......@@ -138,7 +138,7 @@ module QA
16.times do |i|
faker_line_arr = Faker::Lorem.sentences(1500)
content = faker_line_arr.join("\n\r")
create_a_new_file_api_req("hello#{i + 100}.txt", "master", "#{@group_name}%2F#{@project_name}", "Add hello#{i + 100}.txt", content)
create_a_new_file_api_req("hello#{i + 100}.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "Add hello#{i + 100}.txt", content)
content_arr[i] = faker_line_arr
end
......@@ -151,7 +151,7 @@ module QA
update_file_api_req("hello#{i + 100}.txt", "performance", "#{@group_name}%2F#{@project_name}", "Update hello#{i + 100}.txt", content)
end
create_mr_response = create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "performance", "master", "Large_MR")
create_mr_response = create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "performance", Runtime::Env.default_branch, "Large_MR")
iid = JSON.parse(create_mr_response.body)["iid"]
diff_refs = JSON.parse(create_mr_response.body)["diff_refs"]
......@@ -200,7 +200,7 @@ module QA
create_a_branch_api_req(branch_name, project_path)
create_a_new_file_api_req(file_name, branch_name, project_path, "Initial commit for new file", "Initial file content")
create_mr_response = create_a_merge_request_api_req(project_path, branch_name, "master", "MR with many commits-#{SecureRandom.hex(8)}")
create_mr_response = create_a_merge_request_api_req(project_path, branch_name, Runtime::Env.default_branch, "MR with many commits-#{SecureRandom.hex(8)}")
@urls[:mr_with_many_commits] = JSON.parse(create_mr_response.body)["web_url"]
100.times do |i|
update_file_api_req(file_name, branch_name, project_path, Faker::Lorem.sentences(5).join(" "), Faker::Lorem.sentences(500).join("\n"))
......@@ -268,7 +268,7 @@ module QA
def create_a_branch_api_req(branch_name, project_path_or_id)
call_api(expected_response_code: 201) do
post Runtime::API::Request.new(@api_client, "/projects/#{project_path_or_id}/repository/branches").url, "branch=#{branch_name}&ref=master"
post Runtime::API::Request.new(@api_client, "/projects/#{project_path_or_id}/repository/branches").url, "branch=#{branch_name}&ref=#{Runtime::Env.default_branch}"
end
end
......
......@@ -110,7 +110,7 @@ RSpec.describe QA::Git::Repository do
end
describe '#push_changes' do
let(:branch) { 'master' }
let(:branch) { QA::Runtime::Env.default_branch }
let(:call_method) { repository.push_changes }
let(:command) { "git push #{repo_uri_with_credentials} #{branch}" }
......
......@@ -6,6 +6,10 @@ RSpec.describe QA::Resource::Events::Project do
def api_get_path
'/foo'
end
def default_branch
'master'
end
end
end
......@@ -53,7 +57,7 @@ RSpec.describe QA::Resource::Events::Project do
end
describe "#wait_for_push_new_branch" do
it 'waits for a push to master if no branch is given' do
it 'waits for a push to the default branch if no branch is given' do
expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed')
expect { subject.wait_for_push_new_branch }.not_to raise_error
end
......
......@@ -423,17 +423,17 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
end
end
context 'when a pipeline triggered from master runs in gitlab-qa' do
context 'when a pipeline triggered from the default branch runs in gitlab-qa' do
before do
stub_env('CI_PROJECT_NAME', 'gitlab-qa')
described_class.configure_rspec
end
it 'runs on master pipelines' do
it 'runs on default branch pipelines' do
group = describe_successfully do
it('runs on master pipeline given a single pipeline', only: { pipeline: :master } ) {}
it('runs in master given an array of pipelines', only: { pipeline: [:canary, :master] }) {}
it('does not run in non-master pipelines', only: { pipeline: [:nightly, :not_nightly, :not_master] } ) {}
it('does not run in non-default pipelines', only: { pipeline: [:nightly, :not_nightly, :not_master] } ) {}
end
aggregate_failures do
......
......@@ -30,17 +30,17 @@ module QA
)
end
# Require approval from code owners on master
# Require approval from code owners on the default branch
# The default branch is already protected, and we can't update a protected branch via the API (yet)
# so we unprotect it first and then protect it again with the desired parameters
Resource::ProtectedBranch.unprotect_via_api! do |protected_branch|
protected_branch.project = project
protected_branch.branch_name = 'master'
protected_branch.branch_name = project.default_branch
end
Resource::ProtectedBranch.fabricate_via_api! do |protected_branch|
protected_branch.project = project
protected_branch.branch_name = 'master'
protected_branch.branch_name = project.default_branch
protected_branch.new_branch = false
protected_branch.require_code_owner_approval = true
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