content_server 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +15 -0
  2. data/bin/file_utils +118 -0
  3. data/lib/content_data/content_data.rb +114 -48
  4. data/lib/content_server/version.rb +1 -1
  5. data/lib/file_monitoring/file_monitoring.rb +94 -50
  6. data/lib/file_monitoring/monitor_path.rb +196 -113
  7. data/lib/file_utils/file_utils.rb +10 -49
  8. data/lib/networking/tcp.rb +4 -4
  9. data/spec/content_data/content_data_spec.rb +331 -0
  10. data/spec/content_data/validations_spec.rb +5 -0
  11. data/spec/content_server/content_server_spec.rb +5 -0
  12. data/spec/content_server/file_streamer_spec.rb +5 -0
  13. data/spec/file_copy/copy_spec.rb +5 -0
  14. data/spec/file_indexing/index_agent_spec.rb +5 -0
  15. data/spec/networking/tcp_spec.rb +5 -0
  16. data/spec/validations/index_validations_spec.rb +5 -0
  17. metadata +9 -89
  18. data/test/content_data/content_data_test.rb +0 -291
  19. data/test/file_generator/file_generator_spec.rb +0 -85
  20. data/test/file_monitoring/monitor_path_test.rb +0 -189
  21. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000 +0 -1000
  22. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.0 +0 -1000
  23. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.1 +0 -1000
  24. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500 +0 -1500
  25. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.0 +0 -1500
  26. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.1 +0 -1500
  27. data/test/file_monitoring/monitor_path_test/test_file.500 +0 -500
  28. data/test/file_monitoring/monitor_path_test/test_file.500.0 +0 -500
  29. data/test/file_monitoring/monitor_path_test/test_file.500.1 +0 -500
  30. data/test/file_utils/fileutil_mksymlink_test.rb +0 -134
  31. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500 +0 -1500
  32. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.0 +0 -1500
  33. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.1 +0 -1500
  34. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000 +0 -1000
  35. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.0 +0 -1000
  36. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.1 +0 -1000
  37. data/test/file_utils/fileutil_mksymlink_test/test_file.500 +0 -500
  38. data/test/file_utils/fileutil_mksymlink_test/test_file.500.0 +0 -500
  39. data/test/file_utils/fileutil_mksymlink_test/test_file.500.1 +0 -500
  40. data/test/file_utils/time_modification_test.rb +0 -136
  41. data/test/params/params_spec.rb +0 -280
  42. data/test/params/params_test.rb +0 -43
  43. data/test/run_in_background/run_in_background_test.rb +0 -122
  44. data/test/run_in_background/test_app +0 -59
@@ -1,136 +0,0 @@
1
- require 'fileutils'
2
- require 'time'
3
- require 'test/unit'
4
-
5
- require 'content_data'
6
- require 'file_indexing'
7
- require 'file_utils'
8
- require 'log'
9
- require 'params'
10
-
11
- module FileUtils
12
- def FileUtils.parse_time time_str
13
- return nil unless time_str.instance_of? String
14
- seconds_from_epoch = Integer time_str # Not using to_i here because it does not check string is integer.
15
- time = Time.at seconds_from_epoch
16
- end
17
-
18
- module Test
19
- class TestTimeModification < ::Test::Unit::TestCase
20
- # directory where tested files will be placed: __FILE__/time_modification_test
21
- RESOURCES_DIR = File.expand_path(File.dirname(__FILE__) + "/time_modification_test")
22
- # minimal time that will be inserted in content
23
- MOD_TIME_CONTENTS = FileUtils.parse_time("1306527039")
24
- # minimal time that will be inserted in instance
25
- MOD_TIME_INSTANCES = FileUtils.parse_time("1306527039")
26
- #time_str = "2002/02/01 02:23:59.000"
27
- #MOD_TIME_INSTANCES = Time.strftime( time_str, '%Y/%m/%d %H:%M:%S.%L' )
28
- DEVICE_NAME = "hd1"
29
-
30
- @input_db
31
- @mod_content_checksum = nil # checksum of the content that was manually modified
32
- @mod_instance_checksum = nil # checksum of the instance that was manually modified
33
-
34
- def setup
35
- Params.init Array.new
36
- # must preced Log.init, otherwise log containing default values will be created
37
- Params['log_write_to_file'] = false
38
- Params['log_write_to_console'] = false
39
- Log.init
40
-
41
- sizes = [500, 1000, 1500]
42
- numb_of_copies = 2
43
- test_file_name = "test_file"
44
-
45
- Dir.mkdir(RESOURCES_DIR) unless (File.exists?(RESOURCES_DIR))
46
- raise "Can't create writable working directory: #{RESOURCES_DIR}" unless \
47
- (File.exists?(RESOURCES_DIR) and File.writable?(RESOURCES_DIR))
48
- # prepare files for testing
49
- sizes.each do |size|
50
- file_path = "#{RESOURCES_DIR}/#{test_file_name}.#{size}"
51
- file = File.open(file_path, "w", 0777) do |file|
52
- content = Array.new
53
- size.times do |i|
54
- content.push(sprintf("%5d ", i))
55
- end
56
- file.puts(content)
57
- end
58
- File.utime File.atime(file_path), MOD_TIME_CONTENTS, file_path
59
- numb_of_copies.times do |i|
60
- ::FileUtils.cp(file_path, "#{file_path}.#{i}")
61
- end
62
- end
63
-
64
- indexer = FileIndexing::IndexAgent.new
65
- patterns = FileIndexing::IndexerPatterns.new
66
- patterns.add_pattern(RESOURCES_DIR + '\*')
67
- indexer.index(patterns)
68
-
69
- @input_db = indexer.indexed_content
70
- end
71
-
72
- # This test compares two ways of ruby + OS to get mtime (modification file) of a file.
73
- # We can see that in Windows there is a difference.
74
- def test_local_os
75
- Dir.mkdir(RESOURCES_DIR) unless (File.exists?(RESOURCES_DIR))
76
- file_path = "#{RESOURCES_DIR}/local_os_test.test"
77
- file = File.open(file_path, "w", 0777) do |file|
78
- file.puts("kuku")
79
- end
80
- file_stats = File.stat(file_path)
81
- Log.info "MOD_TIME_CONTENTS: #{MOD_TIME_CONTENTS}."
82
- Log.info "MOD_TIME_CONTENTS: #{MOD_TIME_CONTENTS.to_i}."
83
- Log.info "file_stat.mtime: #{file_stats.mtime}."
84
- Log.info "file_stat.mtime: #{file_stats.mtime.to_i}."
85
- Log.info "File.mtime: #{File.mtime(file_path)}."
86
- Log.info "File.mtime: #{File.mtime(file_path).to_i}."
87
- File.utime File.atime(file_path), MOD_TIME_CONTENTS, file_path
88
- file_stats = File.stat(file_path)
89
- Log.info "file_stat.mtime: #{file_stats.mtime}."
90
- Log.info "file_stat.mtime: #{file_stats.mtime.to_i}."
91
- Log.info "File.mtime: #{File.mtime(file_path)}."
92
- Log.info "File.mtime: #{File.mtime(file_path).to_i}."
93
-
94
- file_mtime = nil
95
- file = File.open(file_path, "r") do |file|
96
- Log.info "file.open.mtime = #{file.mtime}"
97
- Log.info "file.open.mtime = #{file.mtime.to_i}"
98
- file_mtime = file.mtime
99
- end
100
-
101
- assert_equal(MOD_TIME_CONTENTS, file_mtime)
102
-
103
- # !!! This fails on windows with different timezone
104
- # assert_equal(MOD_TIME_CONTENTS, file_stats.mtime)
105
- end
106
-
107
- def test_modify
108
- # modified ContentData. Test files also were modified.
109
- mod_db = FileUtils.unify_time(@input_db)
110
-
111
- Log.info "==============="
112
- Log.info @input_db.to_s
113
- Log.info "==============="
114
-
115
- # checking that content was modified according to the instance with minimal time
116
- mod_db.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path|
117
- next unless checksum.eql?(@mod_instance_checksum)
118
- content_time = FileUtils.parse_time(content_mod_time.to_s)
119
- assert_equal(MOD_TIME_INSTANCES, content_time)
120
- instance_time = FileUtils.parse_time(instance_mod_time.to_s)
121
- assert_equal(MOD_TIME_INSTANCES, instance_time)
122
- }
123
-
124
- # checking that files were actually modified
125
- mod_db.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path|
126
- indexer = FileIndexing::IndexAgent.new # (instance.server_name, instance.device)
127
- patterns = FileIndexing::IndexerPatterns.new
128
- patterns.add_pattern(File.dirname(path) + '/*') # this pattern index all files
129
- indexer.index(patterns, mod_db)
130
- assert_equal(indexer.indexed_content, mod_db)
131
- break
132
- }
133
- end
134
- end
135
- end
136
- end
@@ -1,280 +0,0 @@
1
- # Author: Yaron Dror (yaron.dror.bb@gmail.com)
2
- # Description: The file contains 'Param' module tests
3
-
4
- require 'rspec'
5
- require 'yaml'
6
-
7
- require_relative '../../lib/params.rb'
8
-
9
- module Params
10
- # make private methods or Params public for testing capability.
11
- public_class_method :parse_command_line_arguments, \
12
- :raise_error_if_param_exists, :raise_error_if_param_does_not_exist, \
13
- :read_yml_params, :override_param
14
-
15
- module Spec
16
-
17
- describe 'Params::parameter' do
18
-
19
- it 'should define a new parameters' do
20
- Params.string 'par_str', 'sss' ,'desc_str'
21
- Params.integer 'par_int',1 , 'desc_int'
22
- Params.float 'par_float',2.6 , 'desc_float'
23
- Params.boolean 'par_true', true, 'desc_true'
24
- Params.boolean 'par_false',false , 'desc_false'
25
- Params['par_str'].should eq 'sss'
26
- Params['par_int'].should eq 1
27
- Params['par_float'].should eq 2.6
28
- Params['par_true'].should eq true
29
- Params['par_false'].should eq false
30
- end
31
-
32
- it 'should raise an error for wrong parameter type definition.' do
33
- expect { Params::Param.new 'bad_type', 5, 'non_existing_type', 'desc_bad_type' }.to raise_error
34
- end
35
-
36
- it 'should raise an error when trying to define twice the same parameter' do
37
- Params.string 'only_once', '1st' ,''
38
- expect { Params.string 'only_once', '2nd' ,'' }.to raise_error \
39
- "Parameter:'only_once', can only be defined once."
40
- end
41
- end
42
-
43
- describe 'Params::read_yml_params' do
44
- it 'should raise error when yml parameter is not defined' do
45
- expect { Params::read_yml_params StringIO.new 'not_defined: 10' }.to raise_error \
46
- "Parameter:'not_defined' has not been defined and can not be overridden. " \
47
- "It should first be defined through Param module methods:" \
48
- "Params.string, Params.path, Params.integer, Params.float, Params.complex, or Params.boolean."
49
- end
50
-
51
- it 'Will test yml parameter loading' do
52
- # string to other. Will not raise error. Instead a cast is made.
53
- Params.string('tmp4str', 'string_value', 'tmp4 def')
54
- expect { Params::read_yml_params StringIO.new 'tmp4str: strr' }.to_not raise_error
55
- expect { Params::read_yml_params StringIO.new 'tmp4str: 4' }.to_not raise_error
56
- expect { Params::read_yml_params StringIO.new 'tmp4str: 4.5' }.to_not raise_error
57
- expect { Params::read_yml_params StringIO.new 'tmp4str: true' }.to_not raise_error
58
- expect { Params::read_yml_params StringIO.new 'tmp4str: false' }.to_not raise_error
59
-
60
- # override integer with other types.
61
- Params.integer('tmp4int', 1, 'tmp4 def')
62
- expect { Params::read_yml_params StringIO.new 'tmp4int: strr' }.to raise_error \
63
- "Parameter:'tmp4int' type:'Integer' but value type to override " \
64
- "is:'String'."
65
- expect { Params::read_yml_params StringIO.new 'tmp4int: 4' }.to_not raise_error
66
- expect { Params::read_yml_params StringIO.new 'tmp4int: 4.5' }.to raise_error \
67
- "Parameter:'tmp4int' type:'Integer' but value type to override " \
68
- "is:'Float'."
69
- expect { Params::read_yml_params StringIO.new 'tmp4int: true' }.to raise_error \
70
- "Parameter:'tmp4int' type:'Integer' but value type to override " \
71
- "is:'TrueClass'."
72
- expect { Params::read_yml_params StringIO.new 'tmp4int: false' }.to raise_error \
73
- "Parameter:'tmp4int' type:'Integer' but value type to override " \
74
- "is:'FalseClass'."
75
-
76
- # override float with other types.
77
- Params.float('tmp4float', 1.1, 'tmp4 def')
78
- expect { Params::read_yml_params StringIO.new 'tmp4float: strr' }.to raise_error \
79
- "Parameter:'tmp4float' type:'Float' but value type to override " \
80
- "is:'String'."
81
- expect { Params::read_yml_params StringIO.new 'tmp4float: 4' }.to_not raise_error
82
- expect { Params::read_yml_params StringIO.new 'tmp4float: 4.5' }.to_not raise_error
83
- expect { Params::read_yml_params StringIO.new 'tmp4float: true' }.to raise_error \
84
- "Parameter:'tmp4float' type:'Float' but value type to override " \
85
- "is:'TrueClass'."
86
- expect { Params::read_yml_params StringIO.new 'tmp4float: false' }.to raise_error \
87
- "Parameter:'tmp4float' type:'Float' but value type to override " \
88
- "is:'FalseClass'."
89
- # override boolean with other types.
90
- Params.boolean('tmp4true', true, 'tmp4 def')
91
- expect { Params::read_yml_params StringIO.new 'tmp4true: strr' }.to raise_error \
92
- "Parameter:'tmp4true' type:'Boolean' but value type to override " \
93
- "is:'String'."
94
- expect { Params::read_yml_params StringIO.new 'tmp4true: 4' }.to raise_error \
95
- "Parameter:'tmp4true' type:'Boolean' but value type to override " \
96
- "is:'Fixnum'."
97
- expect { Params::read_yml_params StringIO.new 'tmp4true: 4.5' }.to raise_error \
98
- "Parameter:'tmp4true' type:'Boolean' but value type to override " \
99
- "is:'Float'."
100
- expect { Params::read_yml_params StringIO.new 'tmp4true: true' }.to_not raise_error
101
- expect { Params.read_yml_params StringIO.new 'tmp4true: false' }.to_not raise_error
102
-
103
- Params.boolean('tmp4False', true, 'tmp4 def')
104
- expect { Params.read_yml_params StringIO.new 'tmp4False: strr' }.to raise_error \
105
- "Parameter:'tmp4False' type:'Boolean' but value type to override " \
106
- "is:'String'."
107
- expect { Params.read_yml_params StringIO.new 'tmp4False: 4' }.to raise_error \
108
- "Parameter:'tmp4False' type:'Boolean' but value type to override " \
109
- "is:'Fixnum'."
110
- expect { Params.read_yml_params StringIO.new 'tmp4False: 4.5' }.to raise_error \
111
- "Parameter:'tmp4False' type:'Boolean' but value type to override " \
112
- "is:'Float'."
113
- expect { Params.read_yml_params StringIO.new 'tmp4False: true' }.to_not raise_error
114
- expect { Params.read_yml_params StringIO.new 'tmp4False: false' }.to_not raise_error
115
-
116
- end
117
-
118
- it 'should return false when yml file format is bad' do
119
- Params.read_yml_params(StringIO.new 'bad yml format').should eq false
120
- end
121
-
122
- it 'should override defined values with yml values' do
123
- Params.string('tmp5str', 'aaa', 'tmp5 def')
124
- Params.integer('tmp5int', 11, 'tmp5 def')
125
- Params.float('tmp5float', 11.11, 'tmp5 def')
126
- Params.boolean('tmp5true', true, 'tmp5 def')
127
- Params.boolean('tmp5false', false, 'tmp5 def')
128
- Params.read_yml_params StringIO.new "tmp5str: bbb\ntmp5int: 12\ntmp5float: 12.12\n"
129
- Params.read_yml_params StringIO.new "tmp5true: false\ntmp5false: true\n"
130
- Params['tmp5str'].should eq 'bbb'
131
- Params['tmp5int'].should eq 12
132
- Params['tmp5float'].should eq 12.12
133
- Params['tmp5true'].should eq false
134
- Params['tmp5false'].should eq true
135
- end
136
- end
137
-
138
- describe 'Params.parse_command_line_arguments' do
139
- it 'should raise error when command line parameter is not defined' do
140
- expect { Params.parse_command_line_arguments ['--new_param=9]'] }.to raise_error
141
- end
142
-
143
- it 'should parse parameter from command line.' do
144
- # Override string with types.
145
- Params.string('tmp6str', 'dummy', 'tmp6str def')
146
- expect { Params.parse_command_line_arguments ['--tmp6str=9'] }.to_not raise_error
147
- expect { Params.parse_command_line_arguments ['--tmp6str=8.1'] }.to_not raise_error
148
- expect { Params.parse_command_line_arguments ['--tmp6str=ff'] }.to_not raise_error
149
- expect { Params.parse_command_line_arguments ['--tmp6str=true'] }.to_not raise_error
150
- expect { Params.parse_command_line_arguments ['--tmp6str=false'] }.to_not raise_error
151
-
152
- # from fixnum to other types.
153
- Params.integer('tmp6', 8, 'tmp6 def')
154
- expect { Params.parse_command_line_arguments ['--tmp6=9'] }.to_not raise_error
155
- expect { Params.parse_command_line_arguments ['--tmp6=8.1'] }.to raise_error
156
- expect { Params.parse_command_line_arguments ['--tmp6=ff'] }.to raise_error
157
- expect { Params.parse_command_line_arguments ['--tmp6=true'] }.to raise_error
158
- expect { Params.parse_command_line_arguments ['--tmp6=false'] }.to raise_error
159
-
160
- # from float to other types.
161
- Params.float('tmp7', 8.9, 'tmp7 def')
162
- # Casting fix num to float
163
- expect { Params.parse_command_line_arguments ['--tmp7=9'] }.to_not raise_error
164
- expect { Params.parse_command_line_arguments ['--tmp7=3.4'] }.to_not raise_error
165
- expect { Params.parse_command_line_arguments ['--tmp7=ff'] }.to raise_error
166
- expect { Params.parse_command_line_arguments ['--tmp7=true'] }.to raise_error
167
- expect { Params.parse_command_line_arguments ['--tmp7=false'] }.to raise_error
168
-
169
- # from TrueClass to other types.
170
- Params.boolean('tmp8', true, 'tmp8 def')
171
- expect { Params.parse_command_line_arguments ['--tmp8=9'] }.to_not raise_error
172
- expect { Params.parse_command_line_arguments ['--tmp8=3.4'] }.to_not raise_error
173
- expect { Params.parse_command_line_arguments ['--tmp8=ff'] }.to_not raise_error
174
- expect { Params.parse_command_line_arguments ['--tmp8=true'] }.to_not raise_error
175
- expect { Params.parse_command_line_arguments ['--tmp8=false'] }.to_not raise_error
176
-
177
- # from FalseClass to other types.
178
- Params.boolean('tmp9', false, 'tmp9 def')
179
- expect { Params.parse_command_line_arguments ['--tmp9=9'] }.to_not raise_error
180
- expect { Params.parse_command_line_arguments ['--tmp9=3.4'] }.to_not raise_error
181
- expect { Params.parse_command_line_arguments ['--tmp9=ff'] }.to_not raise_error
182
- expect { Params.parse_command_line_arguments ['--tmp9=true'] }.to_not raise_error
183
- expect { Params.parse_command_line_arguments ['--tmp9=false'] }.to_not raise_error
184
- end
185
- end
186
-
187
- describe 'Params.init' do
188
- it 'should override command line arguments correctly.' do
189
- File.stub(:exist?).and_return false
190
- # Override string with types.
191
- Params.string('tmp6str2', 'dummy', 'tmp6str def')
192
- expect { Params.init ['--tmp6str2=9'] }.to_not raise_error
193
- expect { Params.init ['--tmp6str2=8.1'] }.to_not raise_error
194
- expect { Params.init ['--tmp6str2=ff'] }.to_not raise_error
195
- expect { Params.init ['--tmp6str2=true'] }.to_not raise_error
196
- expect { Params.init ['--tmp6str2=false'] }.to_not raise_error
197
-
198
- # from fixnum to other types.
199
- Params.integer('tmp6Fixnum2', 8, 'tmp6 def')
200
- expect { Params.init ['--tmp6Fixnum2=9'] }.to_not raise_error
201
- expect { Params.init ['--tmp6Fixnum2=8.1'] }.to raise_error
202
- expect { Params.init ['--tmp6Fixnum2=ff'] }.to raise_error
203
- expect { Params.init ['--tmp6Fixnum2=true'] }.to raise_error
204
- expect { Params.init ['--tmp6Fixnum2=false'] }.to raise_error
205
-
206
- # from float to other types.
207
- Params.float('tmp7float2', 8.9, 'tmp7 def')
208
- # Casting fix num to float
209
- expect { Params.init ['--tmp7float2=9'] }.to_not raise_error
210
- expect { Params.init ['--tmp7float2=3.4'] }.to_not raise_error
211
- expect { Params.init ['--tmp7float2=ff'] }.to raise_error
212
- expect { Params.init ['--tmp7float2=true'] }.to raise_error
213
- expect { Params.init ['--tmp7float2=false'] }.to raise_error
214
-
215
- # from TrueClass to other types.
216
- Params.boolean('tmp8true2', true, 'tmp8 def')
217
- expect { Params.init ['--tmp8true2=9'] }.to raise_error
218
- expect { Params.init ['--tmp8true2=3.4'] }.to raise_error
219
- expect { Params.init ['--tmp8true2=ff'] }.to raise_error
220
- expect { Params.init ['--tmp8true2=true'] }.to_not raise_error
221
- expect { Params.init ['--tmp8true2=false'] }.to_not raise_error
222
-
223
- # from FalseClass to other types.
224
- Params.boolean('tmp9false2', false, 'tmp9 def')
225
- expect { Params.init ['--tmp9false2=9'] }.to raise_error
226
- expect { Params.init ['--tmp9false2=3.4'] }.to raise_error
227
- expect { Params.init ['--tmp9false2=ff'] }.to raise_error
228
- expect { Params.init ['--tmp9false2=true'] }.to_not raise_error
229
- expect { Params.init ['--tmp9false2=false'] }.to_not raise_error
230
- end
231
-
232
- it 'should override defined values with command line values' do
233
- File.stub(:exist?).and_return false
234
- Params.string('tmp10str', 'aaa', 'tmp10 def')
235
- Params.integer('tmp10int', 11, 'tmp10 def')
236
- Params.float('tmp10float', 11.11, 'tmp10 def')
237
- Params.boolean('tmp10true', true, 'tmp10 def')
238
- Params.boolean('tmp10false', false, 'tmp10 def')
239
- Params.init ['--tmp10str=bbb', '--tmp10int=12', '--tmp10float=12.12', \
240
- '--tmp10true=false', '--tmp10false=true']
241
- Params['tmp10str'].should eq 'bbb'
242
- Params['tmp10int'].should eq 12
243
- Params['tmp10float'].should eq 12.12
244
- Params['tmp10true'].should eq false
245
- Params['tmp10false'].should eq true
246
- end
247
-
248
- it 'init should override parameters with file and command' do
249
- Params.string('init_param', 'code', '')
250
- File.stub(:exist?).and_return true
251
- File.stub(:open).and_return StringIO.new 'init_param: yml'
252
- Params.init ['--conf_file=dummy_file', '--init_param=command-line']
253
- Params['init_param'].should eq 'command-line'
254
- end
255
-
256
- it 'init should override parameters with file only' do
257
- Params.string('init_param2', 'code', '')
258
- File.stub(:exist?).and_return true
259
- File.stub(:open).and_return StringIO.new 'init_param2: yml'
260
- Params.init ['--conf_file=dummy_file']
261
- Params['init_param2'].should eq 'yml'
262
- end
263
-
264
- it 'init should override parameters with command line only' do
265
- Params.string('init_param3', 'code', '')
266
- File.stub(:exist?).and_return false
267
- Params.init ['--init_param3=command-line']
268
- Params['init_param3'].should eq 'command-line'
269
- end
270
-
271
- it 'init should not override any parameters' do
272
- Params.string('init_param4', 'code', '')
273
- File.stub(:exist?).and_return false
274
- Params.init []
275
- Params['init_param4'].should eq 'code'
276
- end
277
- end
278
- end
279
- end
280
-
@@ -1,43 +0,0 @@
1
- # Author: Yaron Dror (yaron.dror.bb@gmail.com)
2
- # Description: Params test file.
3
- # run: rake test.
4
- # Note: This file will be tested along with all project tests.
5
-
6
- #require 'params'
7
- require 'test/unit'
8
- require_relative '../../lib/params.rb'
9
-
10
-
11
- class TestLog < ::Test::Unit::TestCase
12
-
13
- def test_parsing_of_the_defined_parameters
14
- # Define options
15
- Params.integer('remote_server1', 3333,
16
- 'Listening port for backup server content data.')
17
- Params.string('backup_username1', 'tmp', 'Backup server username.')
18
- Params.string('backup_password1', 'tmp', 'Backup server password.')
19
- Params.string('backup_destination_folder1', '',
20
- 'Backup server destination folder, default is the relative local folder.')
21
- Params.string('content_data_path1', File.expand_path('~/.bbfs/var/content.data'),
22
- 'ContentData file path.')
23
- Params.string('monitoring_config_path1', File.expand_path('~/.bbfs/etc/file_monitoring.yml'),
24
- 'Configuration file for monitoring.')
25
- Params.float('time_to_start1', 0.03,
26
- 'Time to start monitoring')
27
-
28
- cmd = ['--remote_server1=2222', '--backup_username1=rami', '--backup_password1=kavana',
29
- '--backup_destination_folder1=C:\Users\Alexey\Backup',
30
- '--content_data_path1=C:\Users\Alexey\Content',
31
- '--monitoring_config_path1=C:\Users\Alexey\Config',
32
- '--time_to_start1=1.5']
33
- Params.init cmd
34
- assert_equal(2222, Params['remote_server1'])
35
- assert_equal('rami', Params['backup_username1'])
36
- assert_equal('kavana', Params['backup_password1'])
37
- assert_equal('C:\Users\Alexey\Backup', Params['backup_destination_folder1'])
38
- assert_equal('C:\Users\Alexey\Content', Params['content_data_path1'])
39
- assert_equal('C:\Users\Alexey\Config', Params['monitoring_config_path1'])
40
- assert_equal(1.5, Params['time_to_start1'])
41
- end
42
- end
43
-