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

configuration_spec.rb « client « click_house « spec « click_house-client « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8cbd64ca6502de68d4b8aa198511581216bb3f33 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ClickHouse::Client::Configuration do
  subject(:configuration) do
    config = described_class.new
    config.http_post_proc = -> {}
    config.json_parser = Object
    config
  end

  describe '#register_database' do
    let(:database_options) do
      {
        database: 'test_db',
        url: 'http://localhost:3333',
        username: 'user',
        password: 'pass',
        variables: {
          join_use_nulls: 1
        }
      }
    end

    it 'registers a database' do
      configuration.register_database(:my_db, **database_options)

      expect(configuration.databases.size).to eq(1)
      database = configuration.databases[:my_db]

      expect(database.uri.to_s).to eq('http://localhost:3333?database=test_db&join_use_nulls=1')
    end

    context 'when adding the same DB multiple times' do
      it 'raises error' do
        configuration.register_database(:my_db, **database_options)
        expect do
          configuration.register_database(:my_db, **database_options)
        end.to raise_error(ClickHouse::Client::ConfigurationError, /database 'my_db' is already registered/)
      end
    end
  end

  describe '#validate!' do
    context 'when `http_post_proc` option is not configured' do
      it 'raises error' do
        configuration.http_post_proc = nil

        expect do
          configuration.validate!
        end.to raise_error(ClickHouse::Client::ConfigurationError, /'http_post_proc' option is not configured/)
      end
    end

    context 'when `json_parser` option is not configured' do
      it 'raises error' do
        configuration.json_parser = nil

        expect do
          configuration.validate!
        end.to raise_error(ClickHouse::Client::ConfigurationError, /'json_parser' option is not configured/)
      end
    end
  end
end