Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
11820e8d
Commit
11820e8d
authored
Feb 07, 2022
by
Mark Lapierre
Committed by
Ramya Authappan
Feb 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use predicate instead of exception
For clearer and simpler logic avoid using exceptions as flow control
parent
2c753f80
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
qa/qa/resource/api_fabricator.rb
qa/qa/resource/api_fabricator.rb
+12
-5
qa/qa/resource/reusable.rb
qa/qa/resource/reusable.rb
+3
-1
No files found.
qa/qa/resource/api_fabricator.rb
View file @
11820e8d
...
@@ -7,11 +7,11 @@ module QA
...
@@ -7,11 +7,11 @@ module QA
module
Resource
module
Resource
module
ApiFabricator
module
ApiFabricator
include
Capybara
::
DSL
include
Capybara
::
DSL
include
Support
::
API
include
Errors
include
Errors
attr_reader
:api_resource
,
:api_response
attr_writer
:api_client
attr_writer
:api_client
attr_accessor
:api_user
attr_accessor
:api_user
,
:api_resource
,
:api_response
def
api_support?
def
api_support?
respond_to?
(
:api_get_path
)
&&
respond_to?
(
:api_get_path
)
&&
...
@@ -48,9 +48,6 @@ module QA
...
@@ -48,9 +48,6 @@ module QA
end
end
end
end
include
Support
::
API
attr_writer
:api_resource
,
:api_response
def
api_put
(
body
=
api_put_body
)
def
api_put
(
body
=
api_put_body
)
response
=
put
(
response
=
put
(
Runtime
::
API
::
Request
.
new
(
api_client
,
api_put_path
).
url
,
Runtime
::
API
::
Request
.
new
(
api_client
,
api_put_path
).
url
,
...
@@ -67,6 +64,16 @@ module QA
...
@@ -67,6 +64,16 @@ module QA
@api_fabrication_http_method
||=
:post
@api_fabrication_http_method
||=
:post
end
end
# Checks if a resource already exists
#
# @return [Boolean] true if the resource returns HTTP status code 200
def
exists?
request
=
Runtime
::
API
::
Request
.
new
(
api_client
,
api_get_path
)
response
=
get
(
request
.
url
)
response
.
code
==
HTTP_STATUS_OK
end
private
private
def
resource_web_url
(
resource
)
def
resource_web_url
(
resource
)
...
...
qa/qa/resource/reusable.rb
View file @
11820e8d
...
@@ -46,7 +46,9 @@ module QA
...
@@ -46,7 +46,9 @@ module QA
# @return [Hash<Symbol, QA::Resource>] the resources that were to be removed.
# @return [Hash<Symbol, QA::Resource>] the resources that were to be removed.
def
remove_all_via_api!
def
remove_all_via_api!
resources
.
each
do
|
reuse_as
,
resource
|
resources
.
each
do
|
reuse_as
,
resource
|
QA
::
Runtime
::
Logger
.
debug
(
"
#{
self
.
name
}
- removing
#{
reuse_as
}
"
)
QA
::
Runtime
::
Logger
.
debug
(
"
#{
self
.
name
}
- removing resource reused as :
#{
reuse_as
}
"
)
next
QA
::
Runtime
::
Logger
.
debug
(
"
#{
self
.
name
}
reused as :
#{
reuse_as
}
has already been removed."
)
unless
resource
.
exists?
resource
.
method
(
:remove_via_api!
).
super_method
.
call
resource
.
method
(
:remove_via_api!
).
super_method
.
call
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment