ralf 0.1.4 → 0.1.5
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.
- data/spec/ralf_spec.rb +86 -42
- metadata +1 -1
data/spec/ralf_spec.rb
CHANGED
@@ -4,6 +4,12 @@ require 'ralf'
|
|
4
4
|
|
5
5
|
describe Ralf do
|
6
6
|
|
7
|
+
before(:all) do
|
8
|
+
@key1 = {:name => 'log/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT', :data => 'This is content for key 1'}
|
9
|
+
@key2 = {:name => 'log/access_log-2010-02-10-00-07-28-EFREUTERGRSGDH', :data => 'This is content for key 2'}
|
10
|
+
@key3 = {:name => 'log/access_log-2010-02-11-00-09-32-SDHTFTFHDDDDDH', :data => 'This is content for key 3'}
|
11
|
+
end
|
12
|
+
|
7
13
|
before(:each) do
|
8
14
|
@default_params = {
|
9
15
|
:config => File.dirname(__FILE__) + '/fixtures/config.yaml',
|
@@ -85,16 +91,16 @@ describe Ralf do
|
|
85
91
|
|
86
92
|
it "should accept a range of 2 dates" do
|
87
93
|
ralf = Ralf.new(@default_params.merge(:date => nil, :range => ['2010-02-10', '2010-02-12']))
|
88
|
-
ralf.range.should eql('2010-02-10
|
94
|
+
ralf.range.to_s.should eql('2010-02-10..2010-02-12')
|
89
95
|
end
|
90
96
|
|
91
97
|
it "should accept a range starting with 1 date" do
|
92
98
|
Date.should_receive(:today).any_number_of_times.and_return(Date.strptime('2010-02-17'))
|
93
99
|
ralf = Ralf.new(@default_params.merge(:date => nil, :range => '2010-02-10'))
|
94
|
-
ralf.range.should eql('2010-02-10
|
100
|
+
ralf.range.to_s.should eql('2010-02-10..2010-02-17')
|
95
101
|
|
96
102
|
ralf = Ralf.new(@default_params.merge(:date => nil, :range => ['2010-02-10']))
|
97
|
-
ralf.range.should eql('2010-02-10
|
103
|
+
ralf.range.to_s.should eql('2010-02-10..2010-02-17')
|
98
104
|
end
|
99
105
|
|
100
106
|
it "should accept a range defined by words" do
|
@@ -104,12 +110,12 @@ describe Ralf do
|
|
104
110
|
)
|
105
111
|
|
106
112
|
ralf = Ralf.new(@default_params.merge(:date => nil, :range => '2 days ago'))
|
107
|
-
ralf.range.should eql('2010-02-15
|
113
|
+
ralf.range.to_s.should eql('2010-02-15..2010-02-17')
|
108
114
|
end
|
109
115
|
|
110
116
|
it "should accept a month and convert it to a range" do
|
111
117
|
ralf = Ralf.new(@default_params.merge(:date => nil, :range => 'january'))
|
112
|
-
ralf.range.should eql('2010-01-01
|
118
|
+
ralf.range.to_s.should eql('2010-01-01..2010-01-31')
|
113
119
|
end
|
114
120
|
|
115
121
|
end
|
@@ -119,11 +125,11 @@ describe Ralf do
|
|
119
125
|
before(:each) do
|
120
126
|
@ralf = Ralf.new(@default_params)
|
121
127
|
@bucket1 = {:name => 'bucket1'}
|
122
|
-
@bucket1.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => true, :targetprefix => "log/access_log-" })
|
123
|
-
@bucket1.should_receive(:name).any_number_of_times.and_return(
|
128
|
+
@bucket1.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => true, :targetprefix => "log/access_log-", :targetbucket => @bucket1[:name] })
|
129
|
+
@bucket1.should_receive(:name).any_number_of_times.and_return(@bucket1[:name])
|
124
130
|
@bucket2 = {:name => 'bucket2'}
|
125
|
-
@bucket2.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => false, :targetprefix => "log/" })
|
126
|
-
@bucket2.should_receive(:name).any_number_of_times.and_return(
|
131
|
+
@bucket2.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => false, :targetprefix => "log/", :targetbucket => @bucket2[:name] })
|
132
|
+
@bucket2.should_receive(:name).any_number_of_times.and_return(@bucket2[:name])
|
127
133
|
end
|
128
134
|
|
129
135
|
it "should find buckets with logging enabled" do
|
@@ -133,35 +139,73 @@ describe Ralf do
|
|
133
139
|
@ralf.buckets_with_logging.should eql([@bucket1])
|
134
140
|
end
|
135
141
|
|
136
|
-
it "should
|
137
|
-
@key1
|
138
|
-
@
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
142
|
+
it "should return the new organized path" do
|
143
|
+
@key1.should_receive(:name).and_return(@key1[:name])
|
144
|
+
@ralf.s3_organized_log_file(@bucket1, @key1).should eql('log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT')
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "logging" do
|
148
|
+
|
149
|
+
before(:each) do
|
150
|
+
@key1.should_receive(:name).any_number_of_times.and_return(@key1[:name])
|
151
|
+
@key2.should_receive(:name).any_number_of_times.and_return(@key2[:name])
|
152
|
+
@key1.should_receive(:data).any_number_of_times.and_return(@key1[:data])
|
153
|
+
@key2.should_receive(:data).any_number_of_times.and_return(@key2[:data])
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should save logging to disk" do
|
157
|
+
@bucket1.should_receive(:keys).any_number_of_times.and_return([@key1, @key2])
|
158
|
+
|
159
|
+
File.should_receive(:makedirs).twice.with('/Users/berl/S3/bucket1/log/2010/02/10').and_return(true)
|
160
|
+
File.should_receive(:exists?).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-07-28-EFREUTERGRSGDH').and_return(true)
|
161
|
+
File.should_receive(:exists?).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT').and_return(false)
|
162
|
+
File.should_receive(:open).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT', "w").and_return(true)
|
163
|
+
|
164
|
+
@ralf.save_logging_to_local_disk(@bucket1, '2010-02-10').should eql([@key1, @key2])
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should save logging for range to disk" do
|
168
|
+
@bucket1.should_receive(:keys).any_number_of_times.and_return([@key1, @key2], [@key3], [])
|
169
|
+
@key3.should_receive(:name).any_number_of_times.and_return(@key3[:name])
|
170
|
+
@key3.should_receive(:data).any_number_of_times.and_return(@key3[:data])
|
171
|
+
|
172
|
+
@ralf.date = nil
|
173
|
+
@ralf.range = ['2010-02-10', '2010-02-12']
|
174
|
+
|
175
|
+
File.should_receive(:exists?).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT').and_return(false)
|
176
|
+
File.should_receive(:exists?).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-07-28-EFREUTERGRSGDH').and_return(true)
|
177
|
+
File.should_receive(:exists?).once.with( '/Users/berl/S3/bucket1/log/2010/02/11/access_log-2010-02-11-00-09-32-SDHTFTFHDDDDDH').and_return(false)
|
178
|
+
File.should_receive(:open).once.with( '/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT', "w").and_return(true)
|
179
|
+
File.should_receive(:open).once.with( '/Users/berl/S3/bucket1/log/2010/02/11/access_log-2010-02-11-00-09-32-SDHTFTFHDDDDDH', "w").and_return(true)
|
180
|
+
|
181
|
+
@ralf.save_logging(@bucket1).class.should eql(Range)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should save logging if a different targetbucket is given" do
|
185
|
+
@ralf.s3.should_receive(:bucket).and_return(@bucket1)
|
186
|
+
@bucket3 = {:name => 'bucket3'}
|
187
|
+
@bucket3.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => false, :targetprefix => "log/", :targetbucket => 'bucket1' })
|
188
|
+
@bucket3.should_receive(:name).any_number_of_times.and_return(@bucket3[:name])
|
189
|
+
@bucket1.should_receive(:keys).any_number_of_times.and_return([@key1, @key2])
|
190
|
+
|
191
|
+
@ralf.save_logging_to_local_disk(@bucket3, '2010-02-10').should eql([@key1, @key2])
|
192
|
+
end
|
148
193
|
|
149
|
-
@ralf.save_logging_to_local_disk(@bucket1).should eql([@key1, @key2])
|
150
194
|
end
|
151
195
|
|
152
196
|
it "should merge all logs" do
|
153
197
|
out_string = StringIO.new
|
154
198
|
|
155
|
-
Dir.should_receive(:glob).with('/Users/berl/S3/
|
156
|
-
['/Users/berl/S3/
|
157
|
-
'/Users/berl/S3/
|
199
|
+
Dir.should_receive(:glob).with('/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10*').and_return(
|
200
|
+
['/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT',
|
201
|
+
'/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-07-28-EFREUTERGRSGDH'])
|
158
202
|
|
159
|
-
File.should_receive(:open).with('/Users/berl/S3/
|
203
|
+
File.should_receive(:open).with('/Users/berl/S3/s3_combined_bucket1_2010-02-10.alf', "w").and_yield(out_string)
|
160
204
|
|
161
205
|
LogMerge::Merger.should_receive(:merge).with(
|
162
206
|
out_string,
|
163
|
-
'/Users/berl/S3/
|
164
|
-
'/Users/berl/S3/
|
207
|
+
'/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT',
|
208
|
+
'/Users/berl/S3/bucket1/log/2010/02/10/access_log-2010-02-10-00-07-28-EFREUTERGRSGDH'
|
165
209
|
)
|
166
210
|
|
167
211
|
@ralf.merge_to_combined(@bucket1)
|
@@ -170,27 +214,27 @@ describe Ralf do
|
|
170
214
|
end
|
171
215
|
|
172
216
|
it "should save logs which have a targetprefix containing a '/'" do
|
173
|
-
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/
|
174
|
-
@ralf.local_log_dirname(@bucket2).should eql('/Users/berl/S3/
|
217
|
+
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/bucket1/log/2010/02/10')
|
218
|
+
@ralf.local_log_dirname(@bucket2).should eql('/Users/berl/S3/bucket2/log/2010/02/10')
|
175
219
|
end
|
176
220
|
|
177
221
|
it "should save to a subdir when a out_seperator is given" do
|
178
|
-
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/
|
222
|
+
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/bucket1/log/2010/02/10')
|
179
223
|
|
180
224
|
@ralf.out_seperator = ':year/w:week'
|
181
|
-
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/
|
225
|
+
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/bucket1/log/2010/w06')
|
182
226
|
end
|
183
227
|
|
184
228
|
it "should get the proper directories" do
|
185
|
-
@
|
229
|
+
@key1.should_receive(:name).and_return('log/access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT')
|
186
230
|
@ralf.local_log_file_basename_prefix(@bucket1).should eql('access_log-')
|
187
|
-
@ralf.local_log_file_basename(@bucket1, @
|
188
|
-
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/
|
231
|
+
@ralf.local_log_file_basename(@bucket1, @key1).should eql('access_log-2010-02-10-00-05-32-ZDRFGTCKUYVJCT')
|
232
|
+
@ralf.local_log_dirname(@bucket1).should eql('/Users/berl/S3/bucket1/log/2010/02/10')
|
189
233
|
|
190
|
-
@
|
234
|
+
@key1.should_receive(:name).and_return('log/2010-02-10-00-05-32-ZDRFGTCKUYVJCT')
|
191
235
|
@ralf.local_log_file_basename_prefix(@bucket2).should eql('')
|
192
|
-
@ralf.local_log_file_basename(@bucket2, @
|
193
|
-
@ralf.local_log_dirname(@bucket2).should eql('/Users/berl/S3/
|
236
|
+
@ralf.local_log_file_basename(@bucket2, @key1).should eql('2010-02-10-00-05-32-ZDRFGTCKUYVJCT')
|
237
|
+
@ralf.local_log_dirname(@bucket2).should eql('/Users/berl/S3/bucket2/log/2010/02/10')
|
194
238
|
end
|
195
239
|
|
196
240
|
end
|
@@ -198,14 +242,14 @@ describe Ralf do
|
|
198
242
|
describe "Conversion" do
|
199
243
|
|
200
244
|
before(:each) do
|
201
|
-
@ralf
|
245
|
+
@ralf = Ralf.new(@default_params)
|
202
246
|
@bucket1 = {:name => 'bucket1'}
|
203
|
-
@bucket1.should_receive(:name).any_number_of_times.and_return('
|
247
|
+
@bucket1.should_receive(:name).any_number_of_times.and_return('bucket1')
|
204
248
|
end
|
205
249
|
|
206
250
|
it "should convert the alf to clf" do
|
207
|
-
File.should_receive(:open).once.with("/Users/berl/S3/
|
208
|
-
File.should_receive(:open).once.with("/Users/berl/S3/
|
251
|
+
File.should_receive(:open).once.with("/Users/berl/S3/s3_combined_bucket1_2010-02-10.log", "w").and_return(File)
|
252
|
+
File.should_receive(:open).once.with("/Users/berl/S3/s3_combined_bucket1_2010-02-10.alf", "r").and_return(File)
|
209
253
|
File.should_receive(:close).once.and_return(true)
|
210
254
|
@ralf.convert_alt_to_clf(@bucket1).should eql(true)
|
211
255
|
end
|