dbi-dbrc 1.2.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +4 -0
- data/{CHANGES → CHANGES.md} +56 -22
- data/Gemfile +3 -0
- data/{MANIFEST → MANIFEST.md} +7 -6
- data/README.md +292 -0
- data/Rakefile +9 -33
- data/certs/djberg96_pub.pem +26 -0
- data/dbi-dbrc.gemspec +17 -5
- data/examples/yml/test_yml.rb +5 -5
- data/lib/dbi-dbrc.rb +3 -0
- data/lib/dbi/dbrc.rb +115 -116
- data/spec/dbi_dbrc_spec.rb +247 -0
- data/spec/dbi_dbrc_xml_spec.rb +101 -0
- data/spec/dbi_dbrc_yml_spec.rb +95 -0
- data/spec/spec_helper.rb +6 -0
- metadata +88 -30
- metadata.gz.sig +0 -0
- data/README +0 -260
- data/test/test_dbi_dbrc.rb +0 -198
- data/test/test_dbi_dbrc_xml.rb +0 -159
- data/test/test_dbi_dbrc_yml.rb +0 -157
@@ -0,0 +1,247 @@
|
|
1
|
+
#########################################################################
|
2
|
+
# dbi_dbrc_spec.rb
|
3
|
+
#
|
4
|
+
# Specs for the base class of DBI::DBRC. This test case should be
|
5
|
+
# run via the 'rake spec' task.
|
6
|
+
#########################################################################
|
7
|
+
require 'dbi/dbrc'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'spec_helper'
|
10
|
+
require 'pp' # Requiring this ahead of fakefs to address a superclass issue.
|
11
|
+
require 'fakefs/spec_helpers'
|
12
|
+
|
13
|
+
RSpec.describe DBI::DBRC do
|
14
|
+
include FakeFS::SpecHelpers
|
15
|
+
|
16
|
+
let(:windows) { File::ALT_SEPARATOR }
|
17
|
+
let(:home) { File.join(Dir.pwd, 'home', 'someone') }
|
18
|
+
let(:dbrc) { File.join(home, '.dbrc') }
|
19
|
+
|
20
|
+
let(:plain) {
|
21
|
+
%q{
|
22
|
+
foo user1 pwd1 Oracle 40 3 60
|
23
|
+
foo user2 pwd2 OCI8 60 4 60
|
24
|
+
bar user1 pwd3 Oracle 30 2 30
|
25
|
+
baz user3 pwd4
|
26
|
+
}.lstrip
|
27
|
+
}
|
28
|
+
|
29
|
+
let(:db_foo){ 'foo' }
|
30
|
+
let(:db_bar){ 'bar' }
|
31
|
+
let(:db_baz){ 'baz' }
|
32
|
+
let(:user1) { 'user1' }
|
33
|
+
let(:user2) { 'user2' }
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(Dir).to receive(:home).and_return(home)
|
37
|
+
FileUtils.mkdir_p(home)
|
38
|
+
File.open(dbrc, 'w'){ |fh| fh.write(plain) }
|
39
|
+
File.chmod(0600, dbrc)
|
40
|
+
|
41
|
+
# FakeFS doesn't implement this yet
|
42
|
+
allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
example "version" do
|
46
|
+
expect(described_class::VERSION).to eq('1.6.0')
|
47
|
+
expect(described_class::VERSION).to be_frozen
|
48
|
+
end
|
49
|
+
|
50
|
+
context "windows", :windows => true do
|
51
|
+
example "constructor raises an error unless the .dbrc file is hidden" do
|
52
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(false)
|
53
|
+
expect{ described_class.new(db_foo, user1) }.to raise_error(described_class::Error)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "constructor" do
|
58
|
+
before do
|
59
|
+
if File::ALT_SEPARATOR
|
60
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
61
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
example "constructor raises an error if the permissions are invalid", :unix => true do
|
66
|
+
File.chmod(0555, dbrc)
|
67
|
+
expect{ described_class.new(db_foo, user1) }.to raise_error(described_class::Error)
|
68
|
+
end
|
69
|
+
|
70
|
+
example "constructor raises an error if no database is provided" do
|
71
|
+
expect{ described_class.new }.to raise_error(ArgumentError)
|
72
|
+
end
|
73
|
+
|
74
|
+
example "constructor works as expected with or without user" do
|
75
|
+
expect{ described_class.new(db_foo, user1) }.not_to raise_error
|
76
|
+
expect{ described_class.new(db_foo, nil) }.not_to raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
example "constructor fails if the database entry doesn't exist" do
|
80
|
+
expect{ described_class.new('bogus', user1) }.to raise_error(DBI::DBRC::Error)
|
81
|
+
end
|
82
|
+
|
83
|
+
example "constructor fails if the user entry doesn't exist" do
|
84
|
+
expect{ described_class.new(db_foo, 'nobody') }.to raise_error(DBI::DBRC::Error)
|
85
|
+
end
|
86
|
+
|
87
|
+
example "constructor fails if the .dbrc file isn't found in the specified directory" do
|
88
|
+
expect{ described_class.new(db_foo, user1, '/bogusXX') }.to raise_error(DBI::DBRC::Error)
|
89
|
+
end
|
90
|
+
|
91
|
+
example "constructor returns expected values for the same database with different users" do
|
92
|
+
dbrc1 = described_class.new(db_foo, user1)
|
93
|
+
dbrc2 = described_class.new(db_foo, user2)
|
94
|
+
expect(dbrc1.database).to eq(dbrc2.database)
|
95
|
+
expect(dbrc1.user).to eq('user1')
|
96
|
+
expect(dbrc2.user).to eq('user2')
|
97
|
+
end
|
98
|
+
|
99
|
+
example "constructor returns expected values for the same user with different database" do
|
100
|
+
dbrc1 = described_class.new(db_foo, user1)
|
101
|
+
dbrc2 = described_class.new(db_bar, user1)
|
102
|
+
expect(dbrc1.user).to eq(dbrc2.user)
|
103
|
+
expect(dbrc1.database).to eq('foo')
|
104
|
+
expect(dbrc2.database).to eq('bar')
|
105
|
+
end
|
106
|
+
|
107
|
+
example "constructor works as expected if some optional fields are not defined" do
|
108
|
+
dbrc = described_class.new(db_baz)
|
109
|
+
expect(dbrc.user).to eq("user3")
|
110
|
+
expect(dbrc.passwd).to eq("pwd4")
|
111
|
+
expect(dbrc.driver).to be_nil
|
112
|
+
expect(dbrc.interval).to be_nil
|
113
|
+
expect(dbrc.timeout).to be_nil
|
114
|
+
expect(dbrc.max_reconn).to be_nil
|
115
|
+
expect(dbrc.dsn).to be_nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "instance methods" do
|
120
|
+
before do
|
121
|
+
if File::ALT_SEPARATOR
|
122
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
123
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
124
|
+
end
|
125
|
+
@dbrc = DBI::DBRC.new(db_foo)
|
126
|
+
end
|
127
|
+
|
128
|
+
example "basic database getter method and aliases" do
|
129
|
+
expect(@dbrc).to respond_to(:database)
|
130
|
+
expect(@dbrc.method(:database)).to eq(@dbrc.method(:db))
|
131
|
+
expect(@dbrc.method(:database)).to eq(@dbrc.method(:host))
|
132
|
+
end
|
133
|
+
|
134
|
+
example "basic database setter method and alias" do
|
135
|
+
expect(@dbrc).to respond_to(:database=)
|
136
|
+
expect(@dbrc.method(:database=)).to eq(@dbrc.method(:db=))
|
137
|
+
end
|
138
|
+
|
139
|
+
example "database method returns expected value" do
|
140
|
+
expect(@dbrc.database).to eq('foo')
|
141
|
+
end
|
142
|
+
|
143
|
+
example "basic dbrc_dir check" do
|
144
|
+
expect(@dbrc).to respond_to(:dbrc_dir)
|
145
|
+
end
|
146
|
+
|
147
|
+
example "dbrc_dir returns the expected value" do
|
148
|
+
expect(@dbrc.dbrc_dir).to eq(home)
|
149
|
+
end
|
150
|
+
|
151
|
+
example "basic dbrc_file check" do
|
152
|
+
expect(@dbrc).to respond_to(:dbrc_file)
|
153
|
+
end
|
154
|
+
|
155
|
+
example "dbrc_file returns the expected value" do
|
156
|
+
expect(File.basename(@dbrc.dbrc_file)).to eq('.dbrc')
|
157
|
+
end
|
158
|
+
|
159
|
+
example "basic dsn getter check" do
|
160
|
+
expect(@dbrc).to respond_to(:dsn)
|
161
|
+
end
|
162
|
+
|
163
|
+
example "dsn method returns the expected value" do
|
164
|
+
expect(@dbrc.dsn).to eq('dbi:Oracle:foo')
|
165
|
+
end
|
166
|
+
|
167
|
+
example "basic dsn setter check" do
|
168
|
+
expect(@dbrc).to respond_to(:dsn=)
|
169
|
+
end
|
170
|
+
|
171
|
+
example "user getter basic check" do
|
172
|
+
expect(@dbrc).to respond_to(:user)
|
173
|
+
end
|
174
|
+
|
175
|
+
example "user method returns expected value" do
|
176
|
+
expect(@dbrc.user).to eq('user1')
|
177
|
+
end
|
178
|
+
|
179
|
+
example "user setter basic check" do
|
180
|
+
expect(@dbrc).to respond_to(:user=)
|
181
|
+
end
|
182
|
+
|
183
|
+
example "password getter basic check and alias" do
|
184
|
+
expect(@dbrc).to respond_to(:password)
|
185
|
+
expect(@dbrc.method(:password)).to eq(@dbrc.method(:passwd))
|
186
|
+
end
|
187
|
+
|
188
|
+
example "password method returns expected value" do
|
189
|
+
expect(@dbrc.password).to eq("pwd1")
|
190
|
+
end
|
191
|
+
|
192
|
+
example "password setter basic check and alias" do
|
193
|
+
expect(@dbrc).to respond_to(:password=)
|
194
|
+
expect(@dbrc.method(:password=)).to eq(@dbrc.method(:passwd=))
|
195
|
+
end
|
196
|
+
|
197
|
+
example "driver getter basic check" do
|
198
|
+
expect(@dbrc).to respond_to(:driver)
|
199
|
+
end
|
200
|
+
|
201
|
+
example "driver method returns expected value" do
|
202
|
+
expect(@dbrc.driver).to eq("Oracle")
|
203
|
+
end
|
204
|
+
|
205
|
+
example "driver setter basic check" do
|
206
|
+
expect(@dbrc).to respond_to(:driver=)
|
207
|
+
end
|
208
|
+
|
209
|
+
example "interval getter basic check" do
|
210
|
+
expect(@dbrc).to respond_to(:interval)
|
211
|
+
end
|
212
|
+
|
213
|
+
example "interval method returns expected value" do
|
214
|
+
expect(@dbrc.interval).to eq(60)
|
215
|
+
end
|
216
|
+
|
217
|
+
example "interval setter basic check" do
|
218
|
+
expect(@dbrc).to respond_to(:interval=)
|
219
|
+
end
|
220
|
+
|
221
|
+
example "timeout getter basic check" do
|
222
|
+
expect(@dbrc).to respond_to(:timeout)
|
223
|
+
expect(@dbrc.method(:timeout)).to eq(@dbrc.method(:time_out))
|
224
|
+
end
|
225
|
+
|
226
|
+
example "timeout method returns expected value" do
|
227
|
+
expect(@dbrc.timeout).to eq(40)
|
228
|
+
end
|
229
|
+
|
230
|
+
example "timeout setter basic check" do
|
231
|
+
expect(@dbrc).to respond_to(:timeout=)
|
232
|
+
end
|
233
|
+
|
234
|
+
example "max_reconn getter basic check" do
|
235
|
+
expect(@dbrc).to respond_to(:max_reconn)
|
236
|
+
expect(@dbrc.method(:max_reconn)).to eq(@dbrc.method(:maximum_reconnects))
|
237
|
+
end
|
238
|
+
|
239
|
+
example "max_reconn method returns expected value" do
|
240
|
+
expect(@dbrc.max_reconn).to eq(3)
|
241
|
+
end
|
242
|
+
|
243
|
+
example "max_reconn setter basic check" do
|
244
|
+
expect(@dbrc).to respond_to(:max_reconn=)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
########################################################################
|
2
|
+
# dbi_dbrc_xml_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the XML specific version of DBI::DBRC. This test case
|
5
|
+
# should be run via the 'rake test' task.
|
6
|
+
########################################################################
|
7
|
+
require 'dbi/dbrc'
|
8
|
+
require 'rspec'
|
9
|
+
require 'pp' # Need this to avoid fakefs error
|
10
|
+
require 'fakefs/spec_helpers'
|
11
|
+
|
12
|
+
RSpec.describe DBI::DBRC::XML, :xml => true do
|
13
|
+
include FakeFS::SpecHelpers
|
14
|
+
|
15
|
+
let(:home) { File.join(Dir.pwd, 'home', 'someone') }
|
16
|
+
let(:dbrc) { File.join(home, '.dbrc') }
|
17
|
+
|
18
|
+
let(:db_foo){ 'foo' }
|
19
|
+
let(:user1) { 'user1' }
|
20
|
+
|
21
|
+
let(:xml){
|
22
|
+
%q{
|
23
|
+
<dbrc>
|
24
|
+
<database name="foo">
|
25
|
+
<user>user1</user>
|
26
|
+
<password>pwd1</password>
|
27
|
+
<driver>Oracle</driver>
|
28
|
+
<interval>60</interval>
|
29
|
+
<timeout>40</timeout>
|
30
|
+
<maximum_reconnects>3</maximum_reconnects>
|
31
|
+
</database>
|
32
|
+
<database name="foo">
|
33
|
+
<user>user2</user>
|
34
|
+
<password>pwd2</password>
|
35
|
+
<driver>OCI8</driver>
|
36
|
+
<interval>60</interval>
|
37
|
+
<timeout>60</timeout>
|
38
|
+
<maximum_reconnects>4</maximum_reconnects>
|
39
|
+
</database>
|
40
|
+
<database name="bar">
|
41
|
+
<user>user1</user>
|
42
|
+
<password>pwd3</password>
|
43
|
+
<driver>Oracle</driver>
|
44
|
+
<interval>30</interval>
|
45
|
+
<timeout>30</timeout>
|
46
|
+
<maximum_reconnects>2</maximum_reconnects>
|
47
|
+
</database>
|
48
|
+
<database name="baz">
|
49
|
+
<user>user3</user>
|
50
|
+
<password>pwd4</password>
|
51
|
+
</database>
|
52
|
+
</dbrc>
|
53
|
+
}.lstrip
|
54
|
+
}
|
55
|
+
|
56
|
+
before do
|
57
|
+
allow(Dir).to receive(:home).and_return(home)
|
58
|
+
|
59
|
+
if File::ALT_SEPARATOR
|
60
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
61
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
FileUtils.mkdir_p(home)
|
65
|
+
File.open(dbrc, 'w'){ |fh| fh.write(xml) }
|
66
|
+
File.chmod(0600, dbrc)
|
67
|
+
|
68
|
+
# FakeFS doesn't implement this yet
|
69
|
+
allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
context "instance methods" do
|
73
|
+
before do
|
74
|
+
@dbrc = described_class.new(db_foo, user1)
|
75
|
+
end
|
76
|
+
|
77
|
+
example "database method returns expected value" do
|
78
|
+
expect(@dbrc.database).to eq('foo')
|
79
|
+
end
|
80
|
+
|
81
|
+
example "password method returns expected value" do
|
82
|
+
expect(@dbrc.password).to eq('pwd1')
|
83
|
+
end
|
84
|
+
|
85
|
+
example "driver method returns expected value" do
|
86
|
+
expect(@dbrc.driver).to eq('Oracle')
|
87
|
+
end
|
88
|
+
|
89
|
+
example "interval method returns expected value" do
|
90
|
+
expect(@dbrc.interval).to eq(60)
|
91
|
+
end
|
92
|
+
|
93
|
+
example "timeout method returns expected value" do
|
94
|
+
expect(@dbrc.timeout).to eq(40)
|
95
|
+
end
|
96
|
+
|
97
|
+
example "maximum_reconnects method returns expected value" do
|
98
|
+
expect(@dbrc.maximum_reconnects).to eq(3)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
########################################################################
|
2
|
+
# dbi_dbrc_yml_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the YAML specific version of DBI::DBRC. This test case
|
5
|
+
# should be run via the 'rake test' task.
|
6
|
+
########################################################################
|
7
|
+
require 'dbi/dbrc'
|
8
|
+
require 'rspec'
|
9
|
+
require 'pp' # Need this to avoid fakefs error
|
10
|
+
require 'fakefs/spec_helpers'
|
11
|
+
|
12
|
+
RSpec.describe DBI::DBRC::YML, :yml => true do
|
13
|
+
include FakeFS::SpecHelpers
|
14
|
+
|
15
|
+
let(:home) { File.join(Dir.pwd, 'home', 'someone') }
|
16
|
+
let(:dbrc) { File.join(home, '.dbrc') }
|
17
|
+
|
18
|
+
let(:db_foo){ 'foo' }
|
19
|
+
let(:user1) { 'user1' }
|
20
|
+
|
21
|
+
let(:yml){
|
22
|
+
%q{
|
23
|
+
- foo:
|
24
|
+
user: user1
|
25
|
+
password: pwd1
|
26
|
+
driver: Oracle
|
27
|
+
interval: 60
|
28
|
+
timeout: 40
|
29
|
+
maximum_reconnects: 3
|
30
|
+
- foo:
|
31
|
+
user: user2
|
32
|
+
password: pwd2
|
33
|
+
driver: OCI8
|
34
|
+
interval: 60
|
35
|
+
timeout: 60
|
36
|
+
maximum_reconnects: 4
|
37
|
+
- bar:
|
38
|
+
user: user1
|
39
|
+
password: pwd3
|
40
|
+
driver: Oracle
|
41
|
+
interval: 30
|
42
|
+
timeout: 30
|
43
|
+
maximum_reconnects: 2
|
44
|
+
- baz:
|
45
|
+
user: user3
|
46
|
+
password: pwd4
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
before do
|
51
|
+
allow(Dir).to receive(:home).and_return(home)
|
52
|
+
|
53
|
+
if File::ALT_SEPARATOR
|
54
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
55
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
56
|
+
end
|
57
|
+
|
58
|
+
FileUtils.mkdir_p(home)
|
59
|
+
File.open(dbrc, 'w'){ |fh| fh.write(yml) }
|
60
|
+
File.chmod(0600, dbrc)
|
61
|
+
|
62
|
+
# FakeFS doesn't implement this yet
|
63
|
+
allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
context "instance methods" do
|
67
|
+
before do
|
68
|
+
@dbrc = described_class.new(db_foo, user1)
|
69
|
+
end
|
70
|
+
|
71
|
+
example "database method returns expected value" do
|
72
|
+
expect(@dbrc.database).to eq('foo')
|
73
|
+
end
|
74
|
+
|
75
|
+
example "password method returns expected value" do
|
76
|
+
expect(@dbrc.password).to eq('pwd1')
|
77
|
+
end
|
78
|
+
|
79
|
+
example "driver method returns expected value" do
|
80
|
+
expect(@dbrc.driver).to eq('Oracle')
|
81
|
+
end
|
82
|
+
|
83
|
+
example "interval method returns expected value" do
|
84
|
+
expect(@dbrc.interval).to eq(60)
|
85
|
+
end
|
86
|
+
|
87
|
+
example "timeout method returns expected value" do
|
88
|
+
expect(@dbrc.timeout).to eq(40)
|
89
|
+
end
|
90
|
+
|
91
|
+
example "maximum_reconnects method returns expected value" do
|
92
|
+
expect(@dbrc.maximum_reconnects).to eq(3)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED