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
4e3981c6
Commit
4e3981c6
authored
Jan 27, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for alert field types
Add more tests for different time format and extract types into constants
parent
e7f900a2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
8 deletions
+21
-8
ee/app/models/alert_management/alert_payload_field.rb
ee/app/models/alert_management/alert_payload_field.rb
+4
-1
ee/lib/gitlab/alert_management/alert_payload_field_extractor.rb
.../gitlab/alert_management/alert_payload_field_extractor.rb
+4
-4
ee/spec/lib/gitlab/alert_management/alert_payload_field_extractor_spec.rb
...ab/alert_management/alert_payload_field_extractor_spec.rb
+8
-0
ee/spec/models/alert_management/alert_payload_field_spec.rb
ee/spec/models/alert_management/alert_payload_field_spec.rb
+1
-1
ee/spec/services/alert_management/extract_alert_payload_fields_service_spec.rb
...t_management/extract_alert_payload_fields_service_spec.rb
+4
-2
No files found.
ee/app/models/alert_management/alert_payload_field.rb
View file @
4e3981c6
...
...
@@ -7,7 +7,10 @@ module AlertManagement
attr_accessor
:project
,
:path
,
:label
,
:type
SUPPORTED_TYPES
=
%w[array datetime string]
.
freeze
ARRAY_TYPE
=
'array'
DATETIME_TYPE
=
'datetime'
STRING_TYPE
=
'string'
SUPPORTED_TYPES
=
[
ARRAY_TYPE
,
DATETIME_TYPE
,
STRING_TYPE
].
freeze
validates
:project
,
presence:
true
validates
:label
,
presence:
true
...
...
ee/lib/gitlab/alert_management/alert_payload_field_extractor.rb
View file @
4e3981c6
...
...
@@ -51,12 +51,12 @@ module Gitlab
def
type_of
(
value
)
case
value
when
Array
::
AlertManagement
::
AlertPayloadField
::
ARRAY_TYPE
when
/^\d{4}/
# assume it's a datetime
'datetime'
::
AlertManagement
::
AlertPayloadField
::
DATETIME_TYPE
when
String
'string'
when
Array
'array'
::
AlertManagement
::
AlertPayloadField
::
STRING_TYPE
end
end
end
...
...
ee/spec/lib/gitlab/alert_management/alert_payload_field_extractor_spec.rb
View file @
4e3981c6
...
...
@@ -23,6 +23,10 @@ RSpec.describe Gitlab::AlertManagement::AlertPayloadFieldExtractor do
}
},
time:
'2020-12-09T12:34:56'
,
time_iso_8601_and_rfc_3339:
'2021-01-27T13:01:11+00:00'
,
# ISO 8601 and RFC 3339
time_iso_8601:
'2021-01-27T13:01:11Z'
,
# ISO 8601
time_iso_8601_short:
'20210127T130111Z'
,
# ISO 8601
time_rfc_3339:
'2021-01-27 13:01:11+00:00'
,
# RFC 3339
discarded_null:
nil
,
discarded_bool_true:
true
,
discarded_bool_false:
false
,
...
...
@@ -36,6 +40,10 @@ RSpec.describe Gitlab::AlertManagement::AlertPayloadFieldExtractor do
a_field
(
%w(nested key)
,
'Key'
,
'string'
),
a_field
(
%w(nested deep key)
,
'Key'
,
'string'
),
a_field
([
'time'
],
'Time'
,
'datetime'
),
a_field
([
'time_iso_8601_and_rfc_3339'
],
'Time iso 8601 and rfc 3339'
,
'datetime'
),
a_field
([
'time_iso_8601'
],
'Time iso 8601'
,
'datetime'
),
a_field
([
'time_iso_8601_short'
],
'Time iso 8601 short'
,
'datetime'
),
a_field
([
'time_rfc_3339'
],
'Time rfc 3339'
,
'datetime'
),
a_field
([
'arr'
],
'Arr'
,
'array'
)
)
end
...
...
ee/spec/models/alert_management/alert_payload_field_spec.rb
View file @
4e3981c6
...
...
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec
.
describe
AlertManagement
::
AlertPayloadField
do
let
(
:alert_payload_field
)
{
build
(
:alert_management_alert_payload_field
)
}
describe
'
.
validations'
do
describe
'validations'
do
subject
{
alert_payload_field
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
...
...
ee/spec/services/alert_management/extract_alert_payload_fields_service_spec.rb
View file @
4e3981c6
...
...
@@ -32,8 +32,8 @@ RSpec.describe AlertManagement::ExtractAlertPayloadFieldsService do
project
.
add_maintainer
(
user_with_permissions
)
end
context
'when payload is
a
valid JSON'
do
context
'when payloa has an acceptable size'
do
context
'when payload is valid JSON'
do
context
'when payloa
d
has an acceptable size'
do
it
'responds with success'
do
is_expected
.
to
be_success
end
...
...
@@ -75,6 +75,8 @@ RSpec.describe AlertManagement::ExtractAlertPayloadFieldsService do
end
context
'without permissions'
do
let_it_be
(
:user
)
{
user_without_permissions
}
it
'returns insufficient permissions error'
do
is_expected
.
to
be_error
expect
(
response
.
message
).
to
eq
(
'Insufficient permissions'
)
...
...
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