Welcome to mirror list, hosted at ThFree Co, Russian Federation.

count_projects_metric_spec.rb « instrumentations « metrics « usage « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28185fb9df4311fbb9e8a67fc82e5e9040406f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountProjectsMetric, feature_category: :service_ping do
  before_all do
    create :project, created_at: 2.months.ago
    create :project, created_at: 21.days.ago
    create :project, created_at: 7.days.ago
  end

  context "with all time frame" do
    let(:expected_value) { 3 }
    let(:expected_query) do
      'SELECT COUNT("projects"."id") FROM "projects"'
    end

    it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' }
  end

  context "with 28d time frame" do
    let(:expected_value) { 2 }
    let(:start) { 30.days.ago.to_fs(:db) }
    let(:finish) { 2.days.ago.to_fs(:db) }
    let(:expected_query) do
      'SELECT COUNT("projects"."id") FROM "projects" ' \
        'WHERE "projects"."created_at" ' \
        "BETWEEN '#{start}' AND '#{finish}'"
    end

    it_behaves_like 'a correct instrumented metric value and query', { time_frame: '28d' }
  end
end