summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-14 12:32:30 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commitd0352e6604915a1a94fbe84252d1606f5adac57c (patch)
tree37b7a8f692e111d117d27a0f6b1078e523e19df2 /spec
parentf932b781a79d9b829001c39bc214372b7efd8610 (diff)
downloadgitlab-ce-d0352e6604915a1a94fbe84252d1606f5adac57c.tar.gz
Added specs for MetricsWorker
Diffstat (limited to 'spec')
-rw-r--r--spec/workers/metrics_worker_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/workers/metrics_worker_spec.rb b/spec/workers/metrics_worker_spec.rb
new file mode 100644
index 00000000000..0d12516c1a3
--- /dev/null
+++ b/spec/workers/metrics_worker_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe MetricsWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ it 'prepares and writes the metrics to InfluxDB' do
+ connection = double(:connection)
+ pool = double(:pool)
+
+ expect(pool).to receive(:with).and_yield(connection)
+ expect(connection).to receive(:write_points).with(an_instance_of(Array))
+ expect(Gitlab::Metrics).to receive(:pool).and_return(pool)
+
+ worker.perform([{ 'series' => 'kittens', 'tags' => {} }])
+ end
+ end
+
+ describe '#prepare_metrics' do
+ it 'returns a Hash with the keys as Symbols' do
+ metrics = worker.prepare_metrics([{ 'values' => {}, 'tags' => {} }])
+
+ expect(metrics).to eq([{ values: {}, tags: {} }])
+ end
+
+ it 'escapes tag values' do
+ metrics = worker.prepare_metrics([
+ { 'values' => {}, 'tags' => { 'foo' => 'bar=' } }
+ ])
+
+ expect(metrics).to eq([{ values: {}, tags: { 'foo' => 'bar\\=' } }])
+ end
+ end
+
+ describe '#escape_value' do
+ it 'escapes an equals sign' do
+ expect(worker.escape_value('foo=')).to eq('foo\\=')
+ end
+ end
+end