rims 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -17
- data/ChangeLog +36 -0
- data/Rakefile +70 -1
- data/lib/rims.rb +3 -5
- data/lib/rims/auth.rb +5 -7
- data/lib/rims/cmd.rb +758 -188
- data/lib/rims/error.rb +8 -10
- data/lib/rims/kvs.rb +4 -0
- data/lib/rims/lock.rb +4 -1
- data/lib/rims/protocol.rb +7 -1
- data/lib/rims/protocol/decoder.rb +24 -7
- data/lib/rims/protocol/parser.rb +1 -1
- data/lib/rims/service.rb +953 -0
- data/lib/rims/version.rb +1 -1
- data/rims.gemspec +2 -0
- data/test/cmd/test_command.rb +999 -0
- data/test/test_auth.rb +3 -1
- data/test/test_cmd.rb +36 -0
- data/test/test_error.rb +22 -78
- data/test/test_protocol_auth.rb +3 -1
- data/test/test_protocol_decoder.rb +6 -3
- data/test/test_service.rb +1120 -0
- metadata +38 -11
- data/lib/rims/daemon.rb +0 -338
- data/lib/rims/server.rb +0 -567
- data/test/test_config.rb +0 -533
- data/test/test_daemon_status_file.rb +0 -169
- data/test/test_daemon_waitpid.rb +0 -72
data/test/test_config.rb
DELETED
@@ -1,533 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'digest'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'logger'
|
6
|
-
require 'pp' if $DEBUG
|
7
|
-
require 'rims'
|
8
|
-
require 'socket'
|
9
|
-
require 'test/unit'
|
10
|
-
require 'yaml'
|
11
|
-
|
12
|
-
module RIMS::Test
|
13
|
-
class ConfigTest < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@base_dir = 'dummy_test_base_dir'
|
16
|
-
end
|
17
|
-
|
18
|
-
def teardown
|
19
|
-
FileUtils.rm_rf(@base_dir)
|
20
|
-
end
|
21
|
-
|
22
|
-
def assert_load_from_base_dir(conf_params)
|
23
|
-
conf = RIMS::Config.new
|
24
|
-
conf.load_config_from_base_dir(conf_params, @base_dir)
|
25
|
-
yield(conf)
|
26
|
-
end
|
27
|
-
private :assert_load_from_base_dir
|
28
|
-
|
29
|
-
def assert_config(conf_params)
|
30
|
-
conf = RIMS::Config.new
|
31
|
-
conf.load(base_dir: @base_dir)
|
32
|
-
conf.load(conf_params)
|
33
|
-
yield(conf)
|
34
|
-
end
|
35
|
-
private :assert_config
|
36
|
-
|
37
|
-
def assert_logging_params(conf_params, expected_params)
|
38
|
-
assert_config(conf_params) {|conf|
|
39
|
-
assert_equal(expected_params, conf.logging_params, 'logging_params')
|
40
|
-
assert_equal({}, conf.through_server_params, 'throuth_server_params')
|
41
|
-
}
|
42
|
-
end
|
43
|
-
private :assert_logging_params
|
44
|
-
|
45
|
-
def assert_key_value_store_params(db_type, conf_params, expected_params)
|
46
|
-
assert_config(conf_params) {|conf|
|
47
|
-
assert_equal(expected_params, conf.key_value_store_params(db_type), 'key_value_store_params')
|
48
|
-
assert_equal({}, conf.through_server_params, 'throuth_server_params')
|
49
|
-
}
|
50
|
-
end
|
51
|
-
private :assert_key_value_store_params
|
52
|
-
|
53
|
-
def assert_build_authentication(conf_params)
|
54
|
-
assert_config(conf_params) {|conf|
|
55
|
-
yield(conf.build_authentication)
|
56
|
-
assert_equal({}, conf.through_server_params, 'throuth_server_params')
|
57
|
-
}
|
58
|
-
end
|
59
|
-
private :assert_build_authentication
|
60
|
-
|
61
|
-
def assert_privilege_params(conf_params, expected_params)
|
62
|
-
assert_config(conf_params) {|conf|
|
63
|
-
if ((expected_params.is_a? Class) && (expected_params <= Exception)) then
|
64
|
-
assert_raise(expected_params) { conf.setup_privilege_params }
|
65
|
-
else
|
66
|
-
conf.setup_privilege_params
|
67
|
-
assert_equal(expected_params, conf.through_server_params)
|
68
|
-
end
|
69
|
-
}
|
70
|
-
end
|
71
|
-
private :assert_privilege_params
|
72
|
-
|
73
|
-
def test_load_from_base_dir
|
74
|
-
assert_load_from_base_dir({}) {|conf|
|
75
|
-
assert_equal(@base_dir, conf.base_dir)
|
76
|
-
assert_equal({}, conf.through_server_params)
|
77
|
-
}
|
78
|
-
|
79
|
-
assert_load_from_base_dir({ ip_addr: '192.168.0.1' }) {|conf|
|
80
|
-
assert_equal(@base_dir, conf.base_dir)
|
81
|
-
assert_equal({ ip_addr: '192.168.0.1' }, conf.through_server_params)
|
82
|
-
}
|
83
|
-
|
84
|
-
assert_load_from_base_dir({ base_dir: 'foo' }) {|conf|
|
85
|
-
assert_equal(File.join(@base_dir, 'foo'), conf.base_dir)
|
86
|
-
assert_equal({}, conf.through_server_params)
|
87
|
-
}
|
88
|
-
|
89
|
-
assert_load_from_base_dir({ base_dir: 'foo', ip_addr: '192.168.0.1' }) {|conf|
|
90
|
-
assert_equal(File.join(@base_dir, 'foo'), conf.base_dir)
|
91
|
-
assert_equal({ ip_addr: '192.168.0.1' }, conf.through_server_params)
|
92
|
-
}
|
93
|
-
|
94
|
-
assert_load_from_base_dir({ base_dir: '/foo' }) {|conf|
|
95
|
-
assert_equal('/foo', conf.base_dir)
|
96
|
-
assert_equal({}, conf.through_server_params)
|
97
|
-
}
|
98
|
-
|
99
|
-
assert_load_from_base_dir({ base_dir: '/foo', ip_addr: '192.168.0.1' }) {|conf|
|
100
|
-
assert_equal('/foo', conf.base_dir)
|
101
|
-
assert_equal({ ip_addr: '192.168.0.1' }, conf.through_server_params)
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_load_libraries
|
106
|
-
assert(! $LOADED_FEATURES.any?{|name| name =~ /prime/})
|
107
|
-
fork{
|
108
|
-
begin
|
109
|
-
assert_config(load_libraries: %w[ prime ]) {|conf|
|
110
|
-
conf.setup_load_libraries
|
111
|
-
assert($LOADED_FEATURES.any?{|name| name =~ /prime/})
|
112
|
-
}
|
113
|
-
rescue
|
114
|
-
exit!(1)
|
115
|
-
end
|
116
|
-
exit!(0)
|
117
|
-
}
|
118
|
-
Process.wait
|
119
|
-
assert_equal(0, $?.exitstatus)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_logging_params
|
123
|
-
assert_logging_params({}, {
|
124
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
125
|
-
log_level: Logger::INFO,
|
126
|
-
log_opt_args: [],
|
127
|
-
log_stdout: Logger::INFO
|
128
|
-
})
|
129
|
-
|
130
|
-
assert_logging_params({ log_level: 'debug' }, {
|
131
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
132
|
-
log_level: Logger::DEBUG,
|
133
|
-
log_opt_args: [],
|
134
|
-
log_stdout: Logger::INFO
|
135
|
-
})
|
136
|
-
|
137
|
-
assert_logging_params({ log_level: 'info' }, {
|
138
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
139
|
-
log_level: Logger::INFO,
|
140
|
-
log_opt_args: [],
|
141
|
-
log_stdout: Logger::INFO
|
142
|
-
})
|
143
|
-
|
144
|
-
assert_logging_params({ log_level: 'warn' }, {
|
145
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
146
|
-
log_level: Logger::WARN,
|
147
|
-
log_opt_args: [],
|
148
|
-
log_stdout: Logger::INFO
|
149
|
-
})
|
150
|
-
|
151
|
-
assert_logging_params({ log_level: 'error' }, {
|
152
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
153
|
-
log_level: Logger::ERROR,
|
154
|
-
log_opt_args: [],
|
155
|
-
log_stdout: Logger::INFO
|
156
|
-
})
|
157
|
-
|
158
|
-
assert_logging_params({ log_stdout: 'debug' }, {
|
159
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
160
|
-
log_level: Logger::INFO,
|
161
|
-
log_opt_args: [],
|
162
|
-
log_stdout: Logger::DEBUG
|
163
|
-
})
|
164
|
-
|
165
|
-
assert_logging_params({ log_stdout: 'info' }, {
|
166
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
167
|
-
log_level: Logger::INFO,
|
168
|
-
log_opt_args: [],
|
169
|
-
log_stdout: Logger::INFO
|
170
|
-
})
|
171
|
-
|
172
|
-
assert_logging_params({ log_stdout: 'warn' }, {
|
173
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
174
|
-
log_level: Logger::INFO,
|
175
|
-
log_opt_args: [],
|
176
|
-
log_stdout: Logger::WARN
|
177
|
-
})
|
178
|
-
|
179
|
-
assert_logging_params({ log_stdout: 'error' }, {
|
180
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
181
|
-
log_level: Logger::INFO,
|
182
|
-
log_opt_args: [],
|
183
|
-
log_stdout: Logger::ERROR
|
184
|
-
})
|
185
|
-
|
186
|
-
assert_logging_params({ log_file: 'server.log' }, {
|
187
|
-
log_file: File.join(@base_dir, 'server.log'),
|
188
|
-
log_level: Logger::INFO,
|
189
|
-
log_opt_args: [],
|
190
|
-
log_stdout: Logger::INFO
|
191
|
-
})
|
192
|
-
|
193
|
-
assert_logging_params({ log_file: 'foo/bar/server.log' }, {
|
194
|
-
log_file: File.join(@base_dir, 'foo/bar/server.log'),
|
195
|
-
log_level: Logger::INFO,
|
196
|
-
log_opt_args: [],
|
197
|
-
log_stdout: Logger::INFO
|
198
|
-
})
|
199
|
-
|
200
|
-
assert_logging_params({ log_file: '/var/rims/server.log' }, {
|
201
|
-
log_file: '/var/rims/server.log',
|
202
|
-
log_level: Logger::INFO,
|
203
|
-
log_opt_args: [],
|
204
|
-
log_stdout: Logger::INFO
|
205
|
-
})
|
206
|
-
|
207
|
-
assert_logging_params({ log_shift_age: 'daily' }, {
|
208
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
209
|
-
log_level: Logger::INFO,
|
210
|
-
log_opt_args: [ 'daily' ],
|
211
|
-
log_stdout: Logger::INFO
|
212
|
-
})
|
213
|
-
|
214
|
-
assert_logging_params({ log_shift_size: 1024**2 }, {
|
215
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
216
|
-
log_level: Logger::INFO,
|
217
|
-
log_opt_args: [ 1, 1024**2 ],
|
218
|
-
log_stdout: Logger::INFO
|
219
|
-
})
|
220
|
-
|
221
|
-
assert_logging_params({ log_shift_age: 10,
|
222
|
-
log_shift_size: 1024**2
|
223
|
-
}, {
|
224
|
-
log_file: File.join(@base_dir, 'imap.log'),
|
225
|
-
log_level: Logger::INFO,
|
226
|
-
log_opt_args: [ 10, 1024**2 ],
|
227
|
-
log_stdout: Logger::INFO
|
228
|
-
})
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_key_value_store_params
|
232
|
-
assert_key_value_store_params(:meta_key_value_store, {}, {
|
233
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
234
|
-
origin_config: {},
|
235
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
236
|
-
})
|
237
|
-
|
238
|
-
assert_key_value_store_params(:meta_key_value_store, {
|
239
|
-
meta_key_value_store: {
|
240
|
-
'plug_in' => 'gdbm'
|
241
|
-
}
|
242
|
-
}, {
|
243
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
244
|
-
origin_config: {},
|
245
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
246
|
-
})
|
247
|
-
|
248
|
-
assert_key_value_store_params(:meta_key_value_store, {
|
249
|
-
meta_key_value_store: {
|
250
|
-
'plug_in' => 'gdbm',
|
251
|
-
'configuration' => { 'foo' => 'bar' }
|
252
|
-
}
|
253
|
-
}, {
|
254
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
255
|
-
origin_config: { 'foo' => 'bar' },
|
256
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
257
|
-
})
|
258
|
-
|
259
|
-
FileUtils.mkdir_p(@base_dir)
|
260
|
-
IO.write(File.join(@base_dir, 'config.yml'), { 'foo' => 'bar' }.to_yaml)
|
261
|
-
|
262
|
-
assert_key_value_store_params(:meta_key_value_store, {
|
263
|
-
meta_key_value_store: {
|
264
|
-
'plug_in' => 'gdbm',
|
265
|
-
'configuration_file' => 'config.yml'
|
266
|
-
}
|
267
|
-
}, {
|
268
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
269
|
-
origin_config: { 'foo' => 'bar' },
|
270
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
271
|
-
})
|
272
|
-
|
273
|
-
assert_key_value_store_params(:meta_key_value_store, {
|
274
|
-
meta_key_value_store: {
|
275
|
-
'use_checksum' => true
|
276
|
-
}
|
277
|
-
}, {
|
278
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
279
|
-
origin_config: {},
|
280
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
281
|
-
})
|
282
|
-
|
283
|
-
assert_key_value_store_params(:meta_key_value_store, {
|
284
|
-
meta_key_value_store: {
|
285
|
-
'use_checksum' => false
|
286
|
-
}
|
287
|
-
}, {
|
288
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
289
|
-
origin_config: {},
|
290
|
-
middleware_key_value_store_list: []
|
291
|
-
})
|
292
|
-
|
293
|
-
# for backward compatibility
|
294
|
-
assert_key_value_store_params(:meta_key_value_store, { key_value_store_type: 'gdbm' }, {
|
295
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
296
|
-
origin_config: {},
|
297
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
298
|
-
})
|
299
|
-
|
300
|
-
# for backward compatibility
|
301
|
-
assert_key_value_store_params(:meta_key_value_store, { use_key_value_store_checksum: true }, {
|
302
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
303
|
-
origin_config: {},
|
304
|
-
middleware_key_value_store_list: [ RIMS::Checksum_KeyValueStore ]
|
305
|
-
})
|
306
|
-
|
307
|
-
# for backward compatibility
|
308
|
-
assert_key_value_store_params(:meta_key_value_store, { use_key_value_store_checksum: false }, {
|
309
|
-
origin_key_value_store: RIMS::GDBM_KeyValueStore,
|
310
|
-
origin_config: {},
|
311
|
-
middleware_key_value_store_list: []
|
312
|
-
})
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_build_authentication
|
316
|
-
username = 'foo'
|
317
|
-
password = 'open_sesame'
|
318
|
-
salt = "\x8F\x16\x63\x6D\x21\xE0\x0F\x3D"
|
319
|
-
|
320
|
-
assert_build_authentication({ username: username, password: password }) {|auth|
|
321
|
-
assert_equal(Socket.gethostname, auth.hostname, 'hostname')
|
322
|
-
assert(auth.authenticate_login(username, password), 'user')
|
323
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
324
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
325
|
-
}
|
326
|
-
|
327
|
-
assert_build_authentication({ username: username, password: password, hostname: 'rims-test' }) {|auth|
|
328
|
-
assert_equal('rims-test', auth.hostname, 'hostname')
|
329
|
-
assert(auth.authenticate_login(username, password), 'user')
|
330
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
331
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
332
|
-
}
|
333
|
-
|
334
|
-
assert_build_authentication({ user_list: [
|
335
|
-
{ 'user' => username, 'pass' => password },
|
336
|
-
{ 'user' => username.succ, 'pass' => password.succ }
|
337
|
-
]
|
338
|
-
}) {|auth|
|
339
|
-
assert(auth.authenticate_login(username, password), 'user 1')
|
340
|
-
assert(auth.authenticate_login(username.succ, password.succ), 'user 2')
|
341
|
-
refute(auth.authenticate_login(username.succ.succ, password.succ.succ), 'user 3')
|
342
|
-
}
|
343
|
-
|
344
|
-
assert_build_authentication({ username: username, password: password,
|
345
|
-
user_list: [
|
346
|
-
{ 'user' => username.succ, 'pass' => password.succ }
|
347
|
-
]
|
348
|
-
}) {|auth|
|
349
|
-
assert(auth.authenticate_login(username, password), 'user 1')
|
350
|
-
assert(auth.authenticate_login(username.succ, password.succ), 'user 2')
|
351
|
-
refute(auth.authenticate_login(username.succ.succ, password.succ.succ), 'user 3')
|
352
|
-
}
|
353
|
-
|
354
|
-
assert_build_authentication({ authentication: [
|
355
|
-
{ 'plug_in' => 'plain',
|
356
|
-
'configuration' => [
|
357
|
-
{ 'user' => username, 'pass' => password }
|
358
|
-
]
|
359
|
-
}
|
360
|
-
]
|
361
|
-
}) {|auth|
|
362
|
-
assert(auth.authenticate_login(username, password), 'user')
|
363
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
364
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
365
|
-
}
|
366
|
-
|
367
|
-
assert_build_authentication({ authentication: [
|
368
|
-
{ 'plug_in' => 'hash',
|
369
|
-
'configuration' => [
|
370
|
-
{ 'user' => username,
|
371
|
-
'hash' => RIMS::Password::HashSource.make_entry(Digest::SHA256, 1000, salt, password).to_s
|
372
|
-
}
|
373
|
-
]
|
374
|
-
}
|
375
|
-
]
|
376
|
-
}) {|auth|
|
377
|
-
assert(auth.authenticate_login(username, password), 'user')
|
378
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
379
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
380
|
-
}
|
381
|
-
|
382
|
-
FileUtils.mkdir_p(@base_dir)
|
383
|
-
IO.write(File.join(@base_dir, 'passwd.yml'), [
|
384
|
-
{ 'user' => username, 'pass' => password }
|
385
|
-
].to_yaml)
|
386
|
-
|
387
|
-
assert_build_authentication({ authentication: [
|
388
|
-
{ 'plug_in' => 'plain',
|
389
|
-
'configuration_file' => 'passwd.yml'
|
390
|
-
}
|
391
|
-
]
|
392
|
-
}) {|auth|
|
393
|
-
assert(auth.authenticate_login(username, password), 'user')
|
394
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
395
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
396
|
-
}
|
397
|
-
|
398
|
-
IO.write(File.join(@base_dir, 'passwd.yml'), [
|
399
|
-
{ 'user' => username,
|
400
|
-
'hash' => RIMS::Password::HashSource.make_entry(Digest::SHA256, 1000, salt, password).to_s
|
401
|
-
}
|
402
|
-
].to_yaml)
|
403
|
-
|
404
|
-
assert_build_authentication({ authentication: [
|
405
|
-
{ 'plug_in' => 'hash',
|
406
|
-
'configuration_file' => 'passwd.yml'
|
407
|
-
}
|
408
|
-
]
|
409
|
-
}) {|auth|
|
410
|
-
assert(auth.authenticate_login(username, password), 'user')
|
411
|
-
refute(auth.authenticate_login(username.succ, password), 'mismatch username')
|
412
|
-
refute(auth.authenticate_login(username, password.succ), 'mismatch password')
|
413
|
-
}
|
414
|
-
end
|
415
|
-
|
416
|
-
def test_setup_privilege_params
|
417
|
-
assert_privilege_params({}, {
|
418
|
-
process_privilege_uid: 65534,
|
419
|
-
process_privilege_gid: 65534
|
420
|
-
})
|
421
|
-
|
422
|
-
assert_privilege_params({ process_privilege_user: 'root',
|
423
|
-
process_privilege_group: '0'
|
424
|
-
}, {
|
425
|
-
process_privilege_uid: 0,
|
426
|
-
process_privilege_gid: 0
|
427
|
-
})
|
428
|
-
|
429
|
-
assert_privilege_params({ process_privilege_user: 0,
|
430
|
-
process_privilege_group: 0
|
431
|
-
}, {
|
432
|
-
process_privilege_uid: 0,
|
433
|
-
process_privilege_gid: 0
|
434
|
-
})
|
435
|
-
|
436
|
-
assert_privilege_params({ process_privilege_user: 'detarame',
|
437
|
-
process_privilege_group: 0
|
438
|
-
},
|
439
|
-
ArgumentError)
|
440
|
-
|
441
|
-
assert_privilege_params({ process_privilege_user: 0,
|
442
|
-
process_privilege_group: :detarame
|
443
|
-
},
|
444
|
-
TypeError)
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
class ConfigPathUtilTest < Test::Unit::TestCase
|
449
|
-
def setup
|
450
|
-
@base_dir = "dummy_test_base_dir.#{$$}"
|
451
|
-
FileUtils.rm_rf(@base_dir) if (File.directory? @base_dir)
|
452
|
-
end
|
453
|
-
|
454
|
-
def teardown
|
455
|
-
FileUtils.rm_rf(@base_dir) unless $DEBUG
|
456
|
-
end
|
457
|
-
|
458
|
-
def test_load_plug_in_configuration
|
459
|
-
assert_equal({},RIMS::Config.load_plug_in_configuration(@base_dir, {}))
|
460
|
-
assert_equal({ 'foo' => 'bar' },
|
461
|
-
RIMS::Config.load_plug_in_configuration(@base_dir,
|
462
|
-
{ 'configuration' => { 'foo' => 'bar' } }))
|
463
|
-
|
464
|
-
FileUtils.mkdir_p(@base_dir)
|
465
|
-
IO.write(File.join(@base_dir, 'config.yml'), { 'foo' => 'bar' }.to_yaml)
|
466
|
-
assert_equal({ 'foo' => 'bar' },
|
467
|
-
RIMS::Config.load_plug_in_configuration(@base_dir,
|
468
|
-
{ 'configuration_file' => 'config.yml' }))
|
469
|
-
|
470
|
-
assert_raise(RuntimeError) {
|
471
|
-
RIMS::Config.load_plug_in_configuration(@base_dir, {
|
472
|
-
'configuration' => { 'foo' => 'bar' },
|
473
|
-
'configuration_file' => 'config.yml'
|
474
|
-
})
|
475
|
-
}
|
476
|
-
end
|
477
|
-
|
478
|
-
def test_mkdir_from_base_dir
|
479
|
-
target_dir = File.join(@base_dir, 'foo', 'bar')
|
480
|
-
Dir.mkdir(@base_dir)
|
481
|
-
|
482
|
-
refute(File.directory? target_dir)
|
483
|
-
assert_equal(target_dir, RIMS::Config.mkdir_from_base_dir(@base_dir, %w[ foo bar ]))
|
484
|
-
assert(File.directory? target_dir)
|
485
|
-
end
|
486
|
-
|
487
|
-
def test_mkdir_from_base_dir_already_exist_dir
|
488
|
-
target_dir = File.join(@base_dir, 'foo', 'bar')
|
489
|
-
FileUtils.mkdir_p(target_dir)
|
490
|
-
|
491
|
-
assert(File.directory? target_dir)
|
492
|
-
assert_nil(RIMS::Config.mkdir_from_base_dir(@base_dir, %w[ foo bar ]))
|
493
|
-
assert(File.directory? target_dir)
|
494
|
-
end
|
495
|
-
|
496
|
-
def test_mkdir_from_base_dir_already_exist_file
|
497
|
-
target_dir = File.join(@base_dir, 'foo', 'bar')
|
498
|
-
FileUtils.mkdir_p(File.dirname(target_dir))
|
499
|
-
FileUtils.touch(target_dir)
|
500
|
-
|
501
|
-
assert(File.file? target_dir)
|
502
|
-
assert_raise(RuntimeError) {
|
503
|
-
RIMS::Config.mkdir_from_base_dir(@base_dir, %w[ foo bar ])
|
504
|
-
}
|
505
|
-
assert(File.file? target_dir)
|
506
|
-
end
|
507
|
-
|
508
|
-
def test_mkdir_from_base_dir_not_exist_base_dir
|
509
|
-
refute(File.directory? @base_dir)
|
510
|
-
assert_raise(RuntimeError) {
|
511
|
-
RIMS::Config.mkdir_from_base_dir(@base_dir, %w[ foo bar ])
|
512
|
-
}
|
513
|
-
refute(File.directory? @base_dir)
|
514
|
-
end
|
515
|
-
|
516
|
-
def test_make_key_value_store_path_name_list
|
517
|
-
assert_equal([ 'v1', 'ab', 'c' ],
|
518
|
-
RIMS::Config.make_key_value_store_path_name_list('v1', 'abc'))
|
519
|
-
assert_equal([ 'v1', 'e3', 'b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ],
|
520
|
-
RIMS::Config.make_key_value_store_path_name_list('v1', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'))
|
521
|
-
assert_equal([ 'v1', 'e3', 'b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'meta_db' ],
|
522
|
-
RIMS::Config.make_key_value_store_path_name_list('v1', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', db_name: 'meta_db'))
|
523
|
-
|
524
|
-
assert_raise(ArgumentError) { RIMS::Config.make_key_value_store_path_name_list('v1', '') }
|
525
|
-
assert_raise(ArgumentError) { RIMS::Config.make_key_value_store_path_name_list('v1', 'ab') }
|
526
|
-
end
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
# Local Variables:
|
531
|
-
# mode: Ruby
|
532
|
-
# indent-tabs-mode: nil
|
533
|
-
# End:
|