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
1e8aec77
Commit
1e8aec77
authored
Apr 08, 2021
by
Scott Hampton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test suite endpoint to GraphQL
Add ability to fetch a specific test suite from a pipeline via GraphQL.
parent
15fbb0da
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
337 additions
and
1 deletion
+337
-1
app/graphql/resolvers/ci/test_suite_resolver.rb
app/graphql/resolvers/ci/test_suite_resolver.rb
+30
-0
app/graphql/types/ci/pipeline_type.rb
app/graphql/types/ci/pipeline_type.rb
+6
-0
app/graphql/types/ci/recent_failures_type.rb
app/graphql/types/ci/recent_failures_type.rb
+20
-0
app/graphql/types/ci/test_case_status_enum.rb
app/graphql/types/ci/test_case_status_enum.rb
+15
-0
app/graphql/types/ci/test_case_type.rb
app/graphql/types/ci/test_case_type.rb
+38
-0
app/graphql/types/ci/test_suite_type.rb
app/graphql/types/ci/test_suite_type.rb
+41
-0
changelogs/unreleased/be-test-suite-graphql.yml
changelogs/unreleased/be-test-suite-graphql.yml
+5
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+70
-0
spec/graphql/resolvers/ci/test_suite_resolver_spec.rb
spec/graphql/resolvers/ci/test_suite_resolver_spec.rb
+53
-0
spec/graphql/types/ci/pipeline_type_spec.rb
spec/graphql/types/ci/pipeline_type_spec.rb
+1
-1
spec/graphql/types/ci/recent_failures_type_spec.rb
spec/graphql/types/ci/recent_failures_type_spec.rb
+15
-0
spec/graphql/types/ci/test_case_status_enum_spec.rb
spec/graphql/types/ci/test_case_status_enum_spec.rb
+13
-0
spec/graphql/types/ci/test_case_type_spec.rb
spec/graphql/types/ci/test_case_type_spec.rb
+15
-0
spec/graphql/types/ci/test_suite_type_spec.rb
spec/graphql/types/ci/test_suite_type_spec.rb
+15
-0
No files found.
app/graphql/resolvers/ci/test_suite_resolver.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
module
Resolvers
module
Ci
class
TestSuiteResolver
<
BaseResolver
type
::
Types
::
Ci
::
TestSuiteType
,
null:
true
alias_method
:pipeline
,
:object
argument
:build_ids
,
[
GraphQL
::
ID_TYPE
],
required:
true
,
description:
'IDs of the builds used to run the test suite.'
def
resolve
(
build_ids
:)
builds
=
pipeline
.
latest_builds
.
id_in
(
build_ids
).
presence
return
if
builds
.
nil?
||
builds
.
empty?
suite
=
builds
.
sum
do
|
build
|
build
.
collect_test_reports!
(
Gitlab
::
Ci
::
Reports
::
TestReports
.
new
)
end
Gitlab
::
Ci
::
Reports
::
TestFailureHistory
.
new
(
suite
.
failed
.
values
,
pipeline
.
project
).
load!
TestSuiteSerializer
.
new
(
project:
pipeline
.
project
,
current_user:
@current_user
)
.
represent
(
suite
,
details:
true
)
end
end
end
end
app/graphql/types/ci/pipeline_type.rb
View file @
1e8aec77
...
...
@@ -128,6 +128,12 @@ module Types
description:
'Summary of the test report generated by the pipeline.'
,
resolver:
Resolvers
::
Ci
::
TestReportSummaryResolver
field
:test_suite
,
Types
::
Ci
::
TestSuiteType
,
null:
false
,
description:
'A specific test suite in a pipeline test report.'
,
resolver:
Resolvers
::
Ci
::
TestSuiteResolver
def
detailed_status
object
.
detailed_status
(
current_user
)
end
...
...
app/graphql/types/ci/recent_failures_type.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
RecentFailuresType
<
BaseObject
graphql_name
'RecentFailures'
description
'Represents the recent failure history of a test case.'
connection_type_class
(
Types
::
CountableConnectionType
)
field
:count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Number of times the test case has failed in the past 14 days.'
field
:base_branch
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the base branch of the project.'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
app/graphql/types/ci/test_case_status_enum.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
module
Types
module
Ci
class
TestCaseStatusEnum
<
BaseEnum
graphql_name
'TestCaseStatus'
::
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_TYPES
.
each
do
|
status
|
value
status
,
description:
"Test case that has a status of
#{
status
}
."
,
value:
status
end
end
end
end
app/graphql/types/ci/test_case_type.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
TestCaseType
<
BaseObject
graphql_name
'TestCase'
description
'Test case in pipeline test report.'
connection_type_class
(
Types
::
CountableConnectionType
)
field
:status
,
Types
::
Ci
::
TestCaseStatusEnum
,
null:
true
,
description:
"Status of the test case (
#{
::
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_TYPES
.
join
(
', '
)
}
)."
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the test case.'
field
:classname
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Classname of the test case.'
field
:execution_time
,
GraphQL
::
FLOAT_TYPE
,
null:
true
,
description:
'Time it took for the test case to finish in seconds.'
field
:file
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Path to the file of the test case.'
field
:system_output
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'System output of the test case.'
field
:stack_trace
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Stack trace of the test case.'
field
:recent_failures
,
Types
::
Ci
::
RecentFailuresType
,
null:
true
,
description:
'Recent failure history of the test case on the base branch.'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
app/graphql/types/ci/test_suite_type.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
TestSuiteType
<
BaseObject
graphql_name
'TestSuite'
description
'Test suite in a pipeline test report.'
connection_type_class
(
Types
::
CountableConnectionType
)
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the test suite.'
field
:total_time
,
GraphQL
::
FLOAT_TYPE
,
null:
true
,
description:
'Total duration of the tests in the test suite.'
field
:total_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Total number of the test cases in the test suite.'
field
:success_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Total number of test cases that succeeded in the test suite.'
field
:failed_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Total number of test cases that failed in the test suite.'
field
:skipped_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Total number of test cases that were skipped in the test suite.'
field
:error_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Total number of test cases that had an error.'
field
:suite_error
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Test suite error message.'
field
:test_cases
,
Types
::
Ci
::
TestCaseType
.
connection_type
,
null:
true
,
description:
'Test cases in the test suite.'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
changelogs/unreleased/be-test-suite-graphql.yml
0 → 100644
View file @
1e8aec77
---
title
:
Add GraphQL endpoint for a specific test suite in pipelines
merge_request
:
58924
author
:
type
:
added
doc/api/graphql/reference/index.md
View file @
1e8aec77
...
...
@@ -4692,6 +4692,7 @@ Information about pagination in a connection.
|
`startedAt`
|
[
`Time`
](
#time
)
| Timestamp when the pipeline was started. |
|
`status`
|
[
`PipelineStatusEnum!`
](
#pipelinestatusenum
)
| Status of the pipeline (CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL, SCHEDULED). |
|
`testReportSummary`
|
[
`TestReportSummary!`
](
#testreportsummary
)
| Summary of the test report generated by the pipeline. |
|
`testSuite`
|
[
`TestSuite!`
](
#testsuite
)
| A specific test suite in a pipeline test report. |
|
`updatedAt`
|
[
`Time!`
](
#time
)
| Timestamp of the pipeline's last activity. |
|
`upstream`
|
[
`Pipeline`
](
#pipeline
)
| Pipeline that triggered the pipeline. |
|
`user`
|
[
`User`
](
#user
)
| Pipeline user. |
...
...
@@ -5141,6 +5142,15 @@ Represents rules that commit pushes must follow.
| ----- | ---- | ----------- |
|
`rejectUnsignedCommits`
|
[
`Boolean!`
](
#boolean
)
| Indicates whether commits not signed through GPG will be rejected. |
### `RecentFailures`
Represents the recent failure history of a test case.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`baseBranch`
|
[
`String`
](
#string
)
| Name of the base branch of the project. |
|
`count`
|
[
`Int`
](
#int
)
| Number of times the test case has failed in the past 14 days. |
### `Release`
Represents a release.
...
...
@@ -6196,6 +6206,41 @@ An edge in a connection.
|
`cursor`
|
[
`String!`
](
#string
)
| A cursor for use in pagination. |
|
`node`
|
[
`TerraformStateVersionRegistry`
](
#terraformstateversionregistry
)
| The item at the end of the edge. |
### `TestCase`
Test case in pipeline test report.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`classname`
|
[
`String`
](
#string
)
| Classname of the test case. |
|
`executionTime`
|
[
`Float`
](
#float
)
| Time it took for the test case to finish in seconds. |
|
`file`
|
[
`String`
](
#string
)
| Path to the file of the test case. |
|
`name`
|
[
`String`
](
#string
)
| Name of the test case. |
|
`recentFailures`
|
[
`RecentFailures`
](
#recentfailures
)
| Recent failure history of the test case on the base branch. |
|
`stackTrace`
|
[
`String`
](
#string
)
| Stack trace of the test case. |
|
`status`
|
[
`TestCaseStatus`
](
#testcasestatus
)
| Status of the test case (error, failed, success, skipped). |
|
`systemOutput`
|
[
`String`
](
#string
)
| System output of the test case. |
### `TestCaseConnection`
The connection type for TestCase.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`count`
|
[
`Int!`
](
#int
)
| Total count of collection. |
|
`edges`
|
[
`[TestCaseEdge]`
](
#testcaseedge
)
| A list of edges. |
|
`nodes`
|
[
`[TestCase]`
](
#testcase
)
| A list of nodes. |
|
`pageInfo`
|
[
`PageInfo!`
](
#pageinfo
)
| Information to aid in pagination. |
### `TestCaseEdge`
An edge in a connection.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`cursor`
|
[
`String!`
](
#string
)
| A cursor for use in pagination. |
|
`node`
|
[
`TestCase`
](
#testcase
)
| The item at the end of the edge. |
### `TestReport`
Represents a requirement test report.
...
...
@@ -6249,6 +6294,22 @@ Total test report statistics.
|
`suiteError`
|
[
`String`
](
#string
)
| Test suite error message. |
|
`time`
|
[
`Float`
](
#float
)
| Total duration of the tests. |
### `TestSuite`
Test suite in a pipeline test report.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`errorCount`
|
[
`Int`
](
#int
)
| Total number of test cases that had an error. |
|
`failedCount`
|
[
`Int`
](
#int
)
| Total number of test cases that failed in the test suite. |
|
`name`
|
[
`String`
](
#string
)
| Name of the test suite. |
|
`skippedCount`
|
[
`Int`
](
#int
)
| Total number of test cases that were skipped in the test suite. |
|
`successCount`
|
[
`Int`
](
#int
)
| Total number of test cases that succeeded in the test suite. |
|
`suiteError`
|
[
`String`
](
#string
)
| Test suite error message. |
|
`testCases`
|
[
`TestCaseConnection`
](
#testcaseconnection
)
| Test cases in the test suite. |
|
`totalCount`
|
[
`Int`
](
#int
)
| Total number of the test cases in the test suite. |
|
`totalTime`
|
[
`Float`
](
#float
)
| Total duration of the tests in the test suite. |
### `TestSuiteSummary`
Test suite summary in a pipeline test report.
...
...
@@ -8269,6 +8330,15 @@ Common sort values.
|
`updated_asc`
**{warning-solid}**
|
**Deprecated:**
This was renamed. Please use
`UPDATED_ASC`
. Deprecated in 13.5. |
|
`updated_desc`
**{warning-solid}**
|
**Deprecated:**
This was renamed. Please use
`UPDATED_DESC`
. Deprecated in 13.5. |
### `TestCaseStatus`
| Value | Description |
| ----- | ----------- |
|
`error`
| Test case that has a status of error. |
|
`failed`
| Test case that has a status of failed. |
|
`skipped`
| Test case that has a status of skipped. |
|
`success`
| Test case that has a status of success. |
### `TestReportState`
State of a test report.
...
...
spec/graphql/resolvers/ci/test_suite_resolver_spec.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
Ci
::
TestSuiteResolver
do
include
GraphqlHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
describe
'#resolve'
do
context
'when pipeline has builds with test reports'
do
let
(
:main_pipeline
)
{
create
(
:ci_pipeline
,
:with_test_reports_with_three_failures
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:with_test_reports_with_three_failures
,
project:
project
,
ref:
'new-feature'
)
}
let
(
:suite_name
)
{
'test'
}
let
(
:build_ids
)
{
pipeline
.
latest_builds
.
pluck
(
:id
)
}
before
do
build
=
main_pipeline
.
builds
.
last
build
.
update_column
(
:finished_at
,
1
.
day
.
ago
)
# Just to be sure we are included in the report window
# The JUnit fixture for the given build has 3 failures.
# This service will create 1 test case failure record for each.
Ci
::
TestFailureHistoryService
.
new
(
main_pipeline
).
execute
end
it
'renders test suite data'
do
test_suite
=
resolve
(
described_class
,
obj:
pipeline
,
args:
{
build_ids:
build_ids
})
expect
(
test_suite
[
:name
]).
to
eq
(
'test'
)
# Each test failure in this pipeline has a matching failure in the default branch
recent_failures
=
test_suite
[
:test_cases
].
map
{
|
tc
|
tc
[
:recent_failures
]
}
expect
(
recent_failures
).
to
eq
([
{
count:
1
,
base_branch:
'master'
},
{
count:
1
,
base_branch:
'master'
},
{
count:
1
,
base_branch:
'master'
}
])
end
end
context
'when pipeline has no builds that matches the given build_ids'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:suite_name
)
{
'test'
}
it
'returns nil'
do
test_suite
=
resolve
(
described_class
,
obj:
pipeline
,
args:
{
build_ids:
[
'1'
]
})
expect
(
test_suite
).
to
eq
(
nil
)
end
end
end
end
spec/graphql/types/ci/pipeline_type_spec.rb
View file @
1e8aec77
...
...
@@ -13,7 +13,7 @@ RSpec.describe Types::Ci::PipelineType do
coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job job downstream
upstream path project active user_permissions warnings commit_path uses_needs
test_report_summary
test_report_summary
test_suite
]
if
Gitlab
.
ee?
...
...
spec/graphql/types/ci/recent_failures_type_spec.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
RecentFailuresType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'RecentFailures'
)
}
it
'contains attributes related to a recent failure history for a test case'
do
expected_fields
=
%w[
count base_branch
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/ci/test_case_status_enum_spec.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
TestCaseStatusEnum
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'TestCaseStatus'
)
}
it
'exposes all test case status types'
do
expect
(
described_class
.
values
.
keys
).
to
eq
(
::
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_TYPES
)
end
end
spec/graphql/types/ci/test_case_type_spec.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
TestCaseType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'TestCase'
)
}
it
'contains attributes related to a pipeline test case'
do
expected_fields
=
%w[
name status classname file execution_time stack_Trace system_output recent_failures
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/ci/test_suite_type_spec.rb
0 → 100644
View file @
1e8aec77
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
TestSuiteType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'TestSuite'
)
}
it
'contains attributes related to a pipeline test suite'
do
expected_fields
=
%w[
name total_time total_count success_count failed_count skipped_count error_count suite_error test_cases
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
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