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
996cf4b6
Commit
996cf4b6
authored
Jul 22, 2019
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor usage data counters specs
This makes these tests available for other implementations
parent
c0c3e7c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
64 deletions
+66
-64
spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb
.../lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb
+9
-64
spec/support/shared_examples/lib/gitlab/usage_data_counters/a_redis_counter.rb
...xamples/lib/gitlab/usage_data_counters/a_redis_counter.rb
+57
-0
No files found.
spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb
View file @
996cf4b6
...
...
@@ -2,68 +2,13 @@
require
'spec_helper'
describe
Gitlab
::
UsageDataCounters
::
WikiPageCounter
,
:clean_gitlab_redis_shared_state
do
shared_examples
:wiki_page_event
do
|
event
|
describe
".count(
#{
event
}
)"
do
it
"increments the wiki page
#{
event
}
counter by 1"
do
expect
do
described_class
.
count
(
event
)
end
.
to
change
{
described_class
.
read
(
event
)
}.
by
1
end
end
describe
".read(
#{
event
}
)"
do
event_count
=
5
it
"returns the total number of
#{
event
}
events"
do
event_count
.
times
do
described_class
.
count
(
event
)
end
expect
(
described_class
.
read
(
event
)).
to
eq
(
event_count
)
end
end
end
include_examples
:wiki_page_event
,
:create
include_examples
:wiki_page_event
,
:update
include_examples
:wiki_page_event
,
:delete
describe
'totals'
do
creations
=
5
edits
=
3
deletions
=
2
before
do
creations
.
times
do
described_class
.
count
(
:create
)
end
edits
.
times
do
described_class
.
count
(
:update
)
end
deletions
.
times
do
described_class
.
count
(
:delete
)
end
end
it
'can report all totals'
do
expect
(
described_class
.
totals
).
to
include
(
wiki_pages_update:
edits
,
wiki_pages_create:
creations
,
wiki_pages_delete:
deletions
)
end
end
describe
'unknown events'
do
error
=
described_class
::
UnknownEvent
it
'cannot increment'
do
expect
{
described_class
.
count
(
:wibble
)
}.
to
raise_error
error
end
it
'cannot read'
do
expect
{
described_class
.
read
(
:wibble
)
}.
to
raise_error
error
end
end
describe
Gitlab
::
UsageDataCounters
::
WikiPageCounter
do
it_behaves_like
'a redis usage counter'
,
'Wiki Page'
,
:create
it_behaves_like
'a redis usage counter'
,
'Wiki Page'
,
:update
it_behaves_like
'a redis usage counter'
,
'Wiki Page'
,
:delete
it_behaves_like
'a redis usage counter with totals'
,
:wiki_pages
,
create:
5
,
update:
3
,
delete:
2
end
spec/support/shared_examples/lib/gitlab/usage_data_counters/a_redis_counter.rb
0 → 100644
View file @
996cf4b6
# frozen_string_literal: true
shared_examples
'a redis usage counter'
do
|
thing
,
event
|
describe
".count(
#{
event
}
)"
,
:clean_gitlab_redis_shared_state
do
it
"increments the
#{
thing
}
#{
event
}
counter by 1"
do
expect
do
described_class
.
count
(
event
)
end
.
to
change
{
described_class
.
read
(
event
)
}.
by
1
end
end
describe
".read(
#{
event
}
)"
,
:clean_gitlab_redis_shared_state
do
event_count
=
5
it
"returns the total number of
#{
event
}
events"
do
event_count
.
times
do
described_class
.
count
(
event
)
end
expect
(
described_class
.
read
(
event
)).
to
eq
(
event_count
)
end
end
end
shared_examples
'a redis usage counter with totals'
do
|
prefix
,
events
|
describe
'totals'
,
:clean_gitlab_redis_shared_state
do
before
do
events
.
each
do
|
k
,
n
|
n
.
times
do
described_class
.
count
(
k
)
end
end
end
let
(
:expected_totals
)
do
events
.
transform_keys
{
|
k
|
"
#{
prefix
}
_
#{
k
}
"
.
to_sym
}
end
it
'can report all totals'
do
expect
(
described_class
.
totals
).
to
include
(
expected_totals
)
end
end
# Override these let-bindings to adjust the unknown events tests
let
(
:unknown_event
)
{
described_class
::
UnknownEvent
}
let
(
:bad_event
)
{
:wibble
}
describe
'unknown events'
do
it
'cannot increment'
do
expect
{
described_class
.
count
(
bad_event
)
}.
to
raise_error
unknown_event
end
it
'cannot read'
do
expect
{
described_class
.
read
(
bad_event
)
}.
to
raise_error
unknown_event
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