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

praefect_spec.rb « setup_helper « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7da6c19d685627ef29decd902667f5ab153c60f (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
79
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SetupHelper::Praefect do
  describe '.configuration_toml' do
    let(:opt_per_repo) do
      { per_repository: true,
        pghost: 'my-host',
        pgport: 555432,
        pguser: 'me' }
    end

    it 'defaults to in memory queue' do
      toml = described_class.configuration_toml('/here', nil, {})

      expect(toml).to match(/i_understand_my_election_strategy_is_unsupported_and_will_be_removed_without_warning/)
      expect(toml).to match(/memory_queue_enabled = true/)
      expect(toml).to match(/election_strategy = "local"/)
      expect(toml).not_to match(/\[database\]/)
    end

    it 'provides database details if wanted' do
      toml = described_class.configuration_toml('/here', nil, opt_per_repo)

      expect(toml).not_to match(/i_understand_my_election_strategy_is_unsupported_and_will_be_removed_without_warning/)
      expect(toml).not_to match(/memory_queue_enabled = true/)
      expect(toml).to match(/\[database\]/)
      expect(toml).to match(/election_strategy = "per_repository"/)
    end

    %i[pghost pgport pguser].each do |pg_key|
      it "fails when #{pg_key} is missing" do
        opt = opt_per_repo.dup
        opt.delete(pg_key)

        expect do
          described_class.configuration_toml('/here', nil, opt)
        end.to raise_error(KeyError)
      end

      it "uses the provided #{pg_key}" do
        toml = described_class.configuration_toml('/here', nil, opt_per_repo)

        expect(toml).to match(/#{pg_key.to_s.delete_prefix('pg')} = "?#{opt_per_repo[pg_key]}"?/)
      end
    end

    it 'defaults to praefect_test if dbname is missing' do
      toml = described_class.configuration_toml('/here', nil, opt_per_repo)

      expect(toml).to match(/dbname = "praefect_test"/)
    end

    it 'uses the provided dbname' do
      opt = opt_per_repo.merge(dbname: 'my_db')

      toml = described_class.configuration_toml('/here', nil, opt)

      expect(toml).to match(/dbname = "my_db"/)
    end
  end

  describe '.get_config_path' do
    it 'defaults to praefect.config.toml' do
      expect(described_class).to receive(:generate_configuration).with(anything, '/tmp/praefect.config.toml', anything)

      described_class.create_configuration('/tmp', {})
    end

    it 'takes the provided config_filename' do
      opt = { config_filename: 'yo.toml' }

      expect(described_class).to receive(:generate_configuration).with(anything, '/tmp/yo.toml', anything)

      described_class.create_configuration('/tmp', {}, options: opt)
    end
  end
end