Skip to content
Snippets Groups Projects
Commit 0c829fcb authored by John McDonnell's avatar John McDonnell :three: Committed by Chloe Liu
Browse files

Add test for Custom Server Hooks on Create Tag API Endpoint

Server admins have the ability to define GL-HOOK-ERR to present a
custom message to clients when a commit is declined or when an
error occurs during the Git commit.
This test verifies that these erorrs are presented on the API level
via testing the create tag API.
parent 845e2cf2
No related branches found
No related tags found
2 merge requests!96059Draft: Add GraphQL query for deployment details,!93509[E2E] Add new test for Custom Server Hooks on Create Tag API Endpoint
......@@ -295,6 +295,21 @@ def change_repository_storage(new_storage)
)
end
def change_path(new_path)
response = put(request_url(api_put_path), path: new_path)
unless response.code == HTTP_STATUS_OK
raise(
ResourceUpdateFailedError,
"Failed to update the project path to '#{new_path}'. Request returned (#{response.code}): `#{response}`."
)
end
# We need to manually set the path_with_namespace as reload! relies on it being correct and avoid 404s
result = parse_body(response)
@path_with_namespace = result[:path_with_namespace]
end
def default_branch
reload!.api_response[:default_branch] || Runtime::Env.default_branch
end
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.initialize_with_readme = true
end
end
context 'when creating a tag for a ref' do
context 'when it triggers a prereceive hook configured with a custom error' do
before do
# The configuration test prereceive hook must match a specific naming pattern
# In this test we create a project with a different name and then change the path.
# Otherwise we wouldn't be able create any commits to be tagged due to the hook.
project.change_path("project-reject-prereceive-#{SecureRandom.hex(8)}")
end
it 'returns a custom server hook error',
:skip_live_env,
except: { job: 'review-qa-*' },
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/369053' do
expect { project.create_repository_tag('v1.2.3') }.to raise_error
.with_message(
/rejecting prereceive hook for projects with GL_PROJECT_PATH matching pattern reject-prereceive/
)
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment