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
e0daf52b
Commit
e0daf52b
authored
Mar 12, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for UsageMetricDefinitionGenerator and refactor
parent
a429b96c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
11 deletions
+21
-11
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
...nerators/gitlab/usage_metric_definition_generator_spec.rb
+21
-11
No files found.
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
View file @
e0daf52b
...
...
@@ -3,10 +3,26 @@
require
'generator_helper'
RSpec
.
describe
Gitlab
::
UsageMetricDefinitionGenerator
do
let
(
:key_path
)
{
'counts_weekly.test_metric'
}
let
(
:dir
)
{
'7d'
}
let
(
:temp_dir
)
{
Dir
.
mktmpdir
}
before
do
stub_const
(
"
#{
described_class
}
::TOP_LEVEL_DIR"
,
temp_dir
)
end
describe
'Creating metric definition file'
do
it
'creates a metric definition file with correct key_path'
do
described_class
.
new
([
key_path
],
{
'dir'
=>
dir
}).
invoke_all
metric_definition_path
=
Dir
.
glob
(
File
.
join
(
temp_dir
,
'metrics/counts_7d/*_test_metric.yml'
)).
first
expect
(
YAML
.
safe_load
(
File
.
read
(
metric_definition_path
))).
to
include
(
"key_path"
=>
key_path
)
end
end
describe
'Validation'
do
let
(
:key_path
)
{
'counter.category.event'
}
let
(
:dir
)
{
'7d'
}
let
(
:options
)
{
[
key_path
,
'--dir'
,
dir
,
'--pretend'
]
}
let
(
:options
)
{
[
key_path
,
'--dir'
,
dir
]
}
subject
{
described_class
.
start
(
options
)
}
...
...
@@ -42,18 +58,12 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator do
end
describe
'Name suggestions'
do
let
(
:temp_dir
)
{
Dir
.
mktmpdir
}
before
do
stub_const
(
"
#{
described_class
}
::TOP_LEVEL_DIR"
,
temp_dir
)
end
context
'with product_intelligence_metrics_names_suggestions feature ON'
do
it
'adds name key to metric definition'
do
stub_feature_flags
(
product_intelligence_metrics_names_suggestions:
true
)
expect
(
::
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
).
to
receive
(
:generate
).
and_return
(
'some name'
)
described_class
.
new
([
'counts_weekly.test_metric'
],
{
'dir'
=>
'7d'
}).
invoke_all
described_class
.
new
([
key_path
],
{
'dir'
=>
dir
}).
invoke_all
metric_definition_path
=
Dir
.
glob
(
File
.
join
(
temp_dir
,
'metrics/counts_7d/*_test_metric.yml'
)).
first
expect
(
YAML
.
safe_load
(
File
.
read
(
metric_definition_path
))).
to
include
(
"name"
=>
"some name"
)
...
...
@@ -65,7 +75,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator do
stub_feature_flags
(
product_intelligence_metrics_names_suggestions:
false
)
expect
(
::
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
).
not_to
receive
(
:generate
)
described_class
.
new
([
'counts_weekly.test_metric'
],
{
'dir'
=>
'7d'
}).
invoke_all
described_class
.
new
([
key_path
],
{
'dir'
=>
dir
}).
invoke_all
metric_definition_path
=
Dir
.
glob
(
File
.
join
(
temp_dir
,
'metrics/counts_7d/*_test_metric.yml'
)).
first
expect
(
YAML
.
safe_load
(
File
.
read
(
metric_definition_path
)).
keys
).
not_to
include
(
:name
)
...
...
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