Commit 6c290834 authored by alinamihaila's avatar alinamihaila

Add tests for events_for_category

parent 3d17057f
...@@ -53,8 +53,10 @@ module Gitlab ...@@ -53,8 +53,10 @@ module Gitlab
Gitlab::Redis::HLL.count(keys: keys) Gitlab::Redis::HLL.count(keys: keys)
end end
# @param category [String] the category name
# @return [Array<String>] list of event names for given category
def events_for_category(category) def events_for_category(category)
known_events.select { |event| event[:category] == category }.map { |event| event[:name] } known_events.select { |event| event[:category] == category.to_s }.map { |event| event[:name] }
end end
private private
......
...@@ -43,6 +43,12 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -43,6 +43,12 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
Timecop.freeze(reference_time) { example.run } Timecop.freeze(reference_time) { example.run }
end end
describe '.events_for_category' do
it 'gets the event names for given category' do
expect(described_class.events_for_category(:analytics)).to contain_exactly(weekly_event, daily_event)
end
end
describe '.track_event' do describe '.track_event' do
it "raise error if metrics don't have same aggregation" do it "raise error if metrics don't have same aggregation" do
expect { described_class.track_event(entity1, different_aggregation, Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation) expect { described_class.track_event(entity1, different_aggregation, Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment