|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -require "spec_helper" |
4 |
| -require "fileutils" |
| 3 | +require 'spec_helper' |
| 4 | +require 'fileutils' |
5 | 5 |
|
6 | 6 | RSpec.describe ChDB::DataPath do
|
7 |
| - let(:test_db_path) { File.join(__dir__, "testdb") } |
| 7 | + let(:test_db_path) { File.join(__dir__, 'testdb') } |
8 | 8 |
|
9 | 9 | before do
|
10 | 10 | FileUtils.rm_rf(test_db_path) if Dir.exist?(test_db_path)
|
11 | 11 | end
|
12 | 12 |
|
13 | 13 | after { FileUtils.remove_entry(test_db_path) if Dir.exist?(test_db_path) }
|
14 | 14 |
|
15 |
| - describe "#initialize" do |
16 |
| - it "parses URI with memory path" do |
17 |
| - path = described_class.new("file::memory:?key1=value1", {}) |
| 15 | + describe '#initialize' do |
| 16 | + it 'parses URI with memory path' do |
| 17 | + path = described_class.new('file::memory:?key1=value1', {}) |
18 | 18 | expect(path.dir_path).to match(/chdb_/)
|
19 | 19 | expect(path.is_tmp).to be true
|
20 |
| - expect(path.query_params.transform_keys(&:to_s)).to include("key1" => "value1") |
| 20 | + expect(path.query_params.transform_keys(&:to_s)).to include('key1' => 'value1') |
21 | 21 | FileUtils.remove_entry(path.dir_path)
|
22 | 22 | end
|
23 | 23 |
|
24 |
| - it "parses URI with file path" do |
| 24 | + it 'parses URI with file path' do |
25 | 25 | path = described_class.new("file:#{test_db_path}?key1=value1", {})
|
26 | 26 | expect(path.dir_path).to eq(test_db_path)
|
27 |
| - expect(path.query_params.transform_keys(&:to_s)).to include("key1" => "value1") |
| 27 | + expect(path.query_params.transform_keys(&:to_s)).to include('key1' => 'value1') |
28 | 28 | end
|
29 | 29 |
|
30 |
| - it "parses URI with query parameters" do |
31 |
| - path = described_class.new("testdb?key1=value1&readonly=1", {}) |
32 |
| - expect(path.query_params).to include("key1" => "value1", "readonly" => "1") |
| 30 | + it 'parses URI with query parameters' do |
| 31 | + path = described_class.new('testdb?key1=value1&readonly=1', {}) |
| 32 | + expect(path.query_params).to include('key1' => 'value1', 'readonly' => '1') |
33 | 33 | end
|
34 | 34 |
|
35 |
| - it "merges options with URI params1" do |
36 |
| - path = described_class.new("test?key1=value1", { results_as_hash: true }) |
37 |
| - expect(path.query_params.transform_keys(&:to_s)).to include("key1" => "value1", "results_as_hash" => true) |
| 35 | + it 'merges options with URI params1' do |
| 36 | + path = described_class.new('test?key1=value1', { results_as_hash: true }) |
| 37 | + expect(path.query_params.transform_keys(&:to_s)).to include('key1' => 'value1', 'results_as_hash' => true) |
38 | 38 | end
|
39 | 39 |
|
40 |
| - it "merges options with URI params2" do |
41 |
| - path = described_class.new("test?key1=value1&results_as_hash=true", { results_as_hash: false }) |
42 |
| - expect(path.query_params.transform_keys(&:to_s)).to include("key1" => "value1", "results_as_hash" => false) |
| 40 | + it 'merges options with URI params2' do |
| 41 | + path = described_class.new('test?key1=value1&results_as_hash=true', { results_as_hash: false }) |
| 42 | + expect(path.query_params.transform_keys(&:to_s)).to include('key1' => 'value1', 'results_as_hash' => false) |
43 | 43 | end
|
44 | 44 | end
|
45 | 45 |
|
46 |
| - describe "#generate_arguments" do |
47 |
| - it "filters special parameters" do |
48 |
| - path = described_class.new(":memory:", results_as_hash: true, flags: 3) |
| 46 | + describe '#generate_arguments' do |
| 47 | + it 'filters special parameters' do |
| 48 | + path = described_class.new(':memory:', results_as_hash: true, flags: 3) |
49 | 49 | args = path.generate_arguments
|
50 | 50 | expect(args).not_to include(a_string_matching(/results_as_hash/))
|
51 | 51 | expect(args).not_to include(a_string_matching(/flags/))
|
52 | 52 | end
|
53 | 53 |
|
54 |
| - it "generates UDF arguments" do |
55 |
| - path = described_class.new("testdb", { udf_path: "/custom/udf" }) |
| 54 | + it 'generates UDF arguments' do |
| 55 | + path = described_class.new('testdb', { udf_path: '/custom/udf' }) |
56 | 56 | args = path.generate_arguments
|
57 |
| - expect(args).to include("--user_scripts_path=/custom/udf") |
58 |
| - expect(args).to include("--user_defined_executable_functions_config=/custom/udf/*.xml") |
| 57 | + expect(args).to include('--user_scripts_path=/custom/udf') |
| 58 | + expect(args).to include('--user_defined_executable_functions_config=/custom/udf/*.xml') |
59 | 59 | end
|
60 | 60 |
|
61 |
| - it "handles normal parameters" do |
62 |
| - path = described_class.new("testdb", { key1: "value1" }) |
| 61 | + it 'handles normal parameters' do |
| 62 | + path = described_class.new('testdb', { key1: 'value1' }) |
63 | 63 | args = path.generate_arguments
|
64 |
| - expect(args).to include("--key1=value1") |
| 64 | + expect(args).to include('--key1=value1') |
65 | 65 | end
|
66 | 66 | end
|
67 | 67 |
|
68 |
| - describe "directory handling" do |
69 |
| - it "creates temp dir for :memory:" do |
70 |
| - path = described_class.new(":memory:", {}) |
| 68 | + describe 'directory handling' do |
| 69 | + it 'creates temp dir for :memory:' do |
| 70 | + path = described_class.new(':memory:', {}) |
71 | 71 | expect(path.dir_path).to match(/chdb_/)
|
72 | 72 | expect(path.is_tmp).to be true
|
73 | 73 | FileUtils.remove_entry(path.dir_path)
|
74 | 74 | end
|
75 | 75 |
|
76 |
| - it "uses existing directory" do |
| 76 | + it 'uses existing directory' do |
77 | 77 | FileUtils.mkdir_p(test_db_path, mode: 0o755) unless Dir.exist?(test_db_path)
|
78 | 78 | path = described_class.new(test_db_path, { flags: 2 })
|
79 | 79 | expect(path.dir_path).to eq(File.expand_path(test_db_path))
|
80 | 80 | expect(path.is_tmp).to be false
|
81 | 81 | FileUtils.remove_entry(path.dir_path)
|
82 | 82 | end
|
83 | 83 |
|
84 |
| - it "raises error when directory not exist without CREATE flag" do |
| 84 | + it 'raises error when directory not exist without CREATE flag' do |
85 | 85 | FileUtils.rm_rf(test_db_path) if Dir.exist?(test_db_path)
|
86 | 86 |
|
87 | 87 | expect do
|
|
92 | 92 | end
|
93 | 93 | end
|
94 | 94 |
|
95 |
| - describe "mode flags" do |
96 |
| - it "sets readonly mode" do |
97 |
| - path = described_class.new("test", { readonly: true }) |
| 95 | + describe 'mode flags' do |
| 96 | + it 'sets readonly mode' do |
| 97 | + path = described_class.new('test', { readonly: true }) |
98 | 98 | expect(path.mode & ChDB::Constants::Open::READONLY).not_to be_zero
|
99 | 99 | end
|
100 | 100 |
|
101 |
| - it "raises error on conflicting flags" do |
| 101 | + it 'raises error on conflicting flags' do |
102 | 102 | expect do
|
103 |
| - described_class.new("test", { readonly: true, flags: ChDB::Constants::Open::READWRITE }) |
| 103 | + described_class.new('test', { readonly: true, flags: ChDB::Constants::Open::READWRITE }) |
104 | 104 | end.to raise_error(ChDB::InvalidArgumentException)
|
105 | 105 | end
|
106 | 106 | end
|
|
0 commit comments