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

post_schema_validator_spec.rb « validator « dashboard « metrics « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7cb1429ca973ce66257995e835ae420e0c94f54 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Metrics::Dashboard::Validator::PostSchemaValidator do
  describe '#validate' do
    context 'with no project and dashboard_path provided' do
      context 'unique local metric_ids' do
        it 'returns empty array' do
          expect(described_class.new(metric_ids: [1, 2, 3]).validate).to eq([])
        end
      end

      context 'duplicate local metrics_ids' do
        it 'returns error' do
          expect(described_class.new(metric_ids: [1, 1]).validate)
            .to eq([Gitlab::Metrics::Dashboard::Validator::Errors::DuplicateMetricIds])
        end
      end
    end

    context 'with project and dashboard_path' do
      let(:project) { create(:project) }

      subject do
        described_class.new(
          project: project,
          metric_ids: ['some_identifier'],
          dashboard_path: 'test/path.yml'
        ).validate
      end

      context 'with unique metric identifiers' do
        before do
          create(:prometheus_metric,
            project: project,
            identifier: 'some_other_identifier',
            dashboard_path: 'test/path.yml'
          )
        end

        it 'returns empty array' do
          expect(subject).to eq([])
        end
      end

      context 'duplicate metric identifiers in database' do
        context 'with different dashboard_path' do
          before do
            create(:prometheus_metric,
              project: project,
              identifier: 'some_identifier',
              dashboard_path: 'some/other/path.yml'
            )
          end

          it 'returns error' do
            expect(subject).to include(Gitlab::Metrics::Dashboard::Validator::Errors::DuplicateMetricIds)
          end
        end

        context 'with same dashboard_path' do
          before do
            create(:prometheus_metric,
              project: project,
              identifier: 'some_identifier',
              dashboard_path: 'test/path.yml'
            )
          end

          it 'returns empty array' do
            expect(subject).to eq([])
          end
        end
      end
    end
  end
end