wvanbergen-request-log-analyzer 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/DESIGN +24 -10
  2. data/bin/request-log-analyzer +2 -27
  3. data/lib/cli/progressbar.rb +2 -19
  4. data/lib/cli/tools.rb +46 -0
  5. data/lib/request_log_analyzer/aggregator/database.rb +16 -5
  6. data/lib/request_log_analyzer/aggregator/echo.rb +1 -0
  7. data/lib/request_log_analyzer/aggregator/summarizer.rb +15 -13
  8. data/lib/request_log_analyzer/controller.rb +8 -4
  9. data/lib/request_log_analyzer/file_format/merb.rb +17 -4
  10. data/lib/request_log_analyzer/file_format/rails_development.rb +30 -92
  11. data/lib/request_log_analyzer/file_format.rb +8 -4
  12. data/lib/request_log_analyzer/filter/anonymize.rb +0 -3
  13. data/lib/request_log_analyzer/filter/field.rb +6 -1
  14. data/lib/request_log_analyzer/filter/timespan.rb +7 -1
  15. data/lib/request_log_analyzer/filter.rb +0 -4
  16. data/lib/request_log_analyzer/line_definition.rb +13 -2
  17. data/lib/request_log_analyzer/output/fixed_width.rb +7 -1
  18. data/lib/request_log_analyzer/output/html.rb +1 -0
  19. data/lib/request_log_analyzer/request.rb +4 -0
  20. data/lib/request_log_analyzer/source/log_parser.rb +19 -21
  21. data/lib/request_log_analyzer/source.rb +2 -1
  22. data/lib/request_log_analyzer/tracker/duration.rb +74 -14
  23. data/lib/request_log_analyzer/tracker/frequency.rb +22 -10
  24. data/lib/request_log_analyzer/tracker/hourly_spread.rb +18 -6
  25. data/lib/request_log_analyzer/tracker/timespan.rb +15 -8
  26. data/lib/request_log_analyzer.rb +4 -8
  27. data/spec/integration/command_line_usage_spec.rb +71 -0
  28. data/spec/lib/helper.rb +33 -0
  29. data/spec/lib/mocks.rb +47 -0
  30. data/spec/{file_formats/spec_format.rb → lib/testing_format.rb} +6 -1
  31. data/spec/spec_helper.rb +5 -41
  32. data/spec/{database_inserter_spec.rb → unit/aggregator/database_inserter_spec.rb} +40 -37
  33. data/spec/unit/aggregator/summarizer_spec.rb +28 -0
  34. data/spec/unit/controller/controller_spec.rb +43 -0
  35. data/spec/{log_processor_spec.rb → unit/controller/log_processor_spec.rb} +4 -3
  36. data/spec/{file_format_spec.rb → unit/file_format/file_format_api_spec.rb} +16 -4
  37. data/spec/{line_definition_spec.rb → unit/file_format/line_definition_spec.rb} +13 -6
  38. data/spec/{merb_format_spec.rb → unit/file_format/merb_format_spec.rb} +2 -2
  39. data/spec/{rails_format_spec.rb → unit/file_format/rails_format_spec.rb} +19 -11
  40. data/spec/unit/filter/anonymize_filter_spec.rb +22 -0
  41. data/spec/unit/filter/field_filter_spec.rb +69 -0
  42. data/spec/unit/filter/timespan_filter_spec.rb +61 -0
  43. data/spec/{log_parser_spec.rb → unit/source/log_parser_spec.rb} +7 -7
  44. data/spec/{request_spec.rb → unit/source/request_spec.rb} +5 -5
  45. data/spec/unit/tracker/duration_tracker_spec.rb +90 -0
  46. data/spec/unit/tracker/frequency_tracker_spec.rb +83 -0
  47. data/spec/unit/tracker/timespan_tracker_spec.rb +64 -0
  48. data/spec/unit/tracker/tracker_api_test.rb +45 -0
  49. metadata +50 -26
  50. data/spec/controller_spec.rb +0 -64
  51. data/spec/filter_spec.rb +0 -157
  52. data/spec/summarizer_spec.rb +0 -9
@@ -1,45 +1,41 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- require 'request_log_analyzer/aggregator/database'
3
-
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
2
 
5
3
  describe RequestLogAnalyzer::Aggregator::Database, "schema creation" do
6
4
 
7
- TEST_DATABASE_FILE = File.dirname(__FILE__) + "/fixtures/requests.db"
8
- include RequestLogAnalyzerSpecHelper
9
-
5
+ include RequestLogAnalyzer::Spec::Helper
6
+
10
7
  before(:each) do
11
- log_parser = RequestLogAnalyzer::Source::LogParser.new(spec_format)
12
- @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => TEST_DATABASE_FILE)
13
- end
14
-
15
- after(:each) do
16
- File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
8
+ log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
9
+ @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => ':memory:')
17
10
  end
11
+
18
12
 
19
13
  it "should create the correct tables" do
20
14
  ActiveRecord::Migration.should_receive(:create_table).with("warnings")
21
15
  ActiveRecord::Migration.should_receive(:create_table).with("requests")
22
16
  ActiveRecord::Migration.should_receive(:create_table).with("first_lines")
23
17
  ActiveRecord::Migration.should_receive(:create_table).with("test_lines")
24
- ActiveRecord::Migration.should_receive(:create_table).with("last_lines")
18
+ ActiveRecord::Migration.should_receive(:create_table).with("eval_lines")
19
+ ActiveRecord::Migration.should_receive(:create_table).with("last_lines")
25
20
 
21
+ ActiveRecord::Migration.should_receive(:add_index).with("eval_lines", [:request_id])
26
22
  ActiveRecord::Migration.should_receive(:add_index).with("first_lines", [:request_id])
27
- ActiveRecord::Migration.should_receive(:add_index).with("test_lines", [:request_id])
28
- ActiveRecord::Migration.should_receive(:add_index).with("last_lines", [:request_id])
23
+ ActiveRecord::Migration.should_receive(:add_index).with("test_lines", [:request_id])
24
+ ActiveRecord::Migration.should_receive(:add_index).with("last_lines", [:request_id])
29
25
 
30
26
  @database_inserter.prepare
31
27
  end
32
28
 
33
29
  it "should create a default Request class" do
34
30
  @database_inserter.prepare
35
- SpecFormat::Database::Request.ancestors.should include(ActiveRecord::Base)
36
- SpecFormat::Database::Request.column_names.should include('first_lineno')
37
- SpecFormat::Database::Request.column_names.should include('last_lineno')
31
+ TestingFormat::Database::Request.ancestors.should include(ActiveRecord::Base)
32
+ TestingFormat::Database::Request.column_names.should include('first_lineno')
33
+ TestingFormat::Database::Request.column_names.should include('last_lineno')
38
34
  end
39
35
 
40
36
  it "should create associations for the default Request class" do
41
37
  @database_inserter.prepare
42
- @request = SpecFormat::Database::Request.new
38
+ @request = TestingFormat::Database::Request.new
43
39
  @request.should respond_to(:test_lines)
44
40
  @request.test_lines.should
45
41
  end
@@ -47,7 +43,7 @@ describe RequestLogAnalyzer::Aggregator::Database, "schema creation" do
47
43
  it "should create the default table names" do
48
44
  @database_inserter.prepare
49
45
  @database_inserter.file_format.line_definitions.each do |name, definition|
50
- klass = SpecFormat::Database.const_get("#{name}_line".camelize)
46
+ klass = TestingFormat::Database.const_get("#{name}_line".camelize)
51
47
  klass.column_names.should include('id')
52
48
  klass.column_names.should include('lineno')
53
49
  klass.column_names.should include('request_id')
@@ -57,46 +53,53 @@ describe RequestLogAnalyzer::Aggregator::Database, "schema creation" do
57
53
  it "should create the correct fields in the table" do
58
54
  @database_inserter.prepare
59
55
 
60
- SpecFormat::Database::FirstLine.column_names.should include('request_no')
61
- SpecFormat::Database::LastLine.column_names.should include('request_no')
62
- SpecFormat::Database::TestLine.column_names.should include('test_capture')
56
+ TestingFormat::Database::FirstLine.column_names.should include('request_no')
57
+ TestingFormat::Database::LastLine.column_names.should include('request_no')
58
+ TestingFormat::Database::TestLine.column_names.should include('test_capture')
59
+ end
60
+
61
+ it "should create fields for provides" do
62
+ @database_inserter.prepare
63
+ TestingFormat::Database::EvalLine.column_names.should include('evaluated')
64
+ TestingFormat::Database::EvalLine.column_names.should include('greating')
65
+ TestingFormat::Database::EvalLine.column_names.should include('what')
63
66
  end
64
67
 
65
68
  end
66
69
 
67
70
  describe RequestLogAnalyzer::Aggregator::Database, "record insertion" do
68
- include RequestLogAnalyzerSpecHelper
71
+ include RequestLogAnalyzer::Spec::Helper
69
72
 
70
73
  before(:each) do
71
- log_parser = RequestLogAnalyzer::Source::LogParser.new(spec_format)
72
- @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => TEST_DATABASE_FILE)
74
+ log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
75
+ @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => ':memory:')
73
76
  @database_inserter.prepare
74
77
 
75
- @incomplete_request = spec_format.create_request( {:line_type => :first, :request_no => 564})
76
- @completed_request = spec_format.create_request( {:line_type => :first, :request_no => 564}, {:line_type => :test, :test_capture => "awesome"},
77
- {:line_type => :test, :test_capture => "indeed"}, {:line_type => :last, :request_no => 564})
78
+ @incomplete_request = testing_format.request( {:line_type => :first, :request_no => 564})
79
+ @completed_request = testing_format.request( {:line_type => :first, :request_no => 564},
80
+ {:line_type => :test, :test_capture => "awesome"},
81
+ {:line_type => :test, :test_capture => "indeed"},
82
+ {:line_type => :eval, :evaluated => "{ 'greating' => 'howdy'}", :greating => 'howdy' },
83
+ {:line_type => :last, :request_no => 564})
78
84
  end
79
85
 
80
- after(:each) do
81
- File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
82
- end
83
-
84
86
  it "should insert a record in the request table" do
85
- SpecFormat::Database::Request.count.should == 0
87
+ TestingFormat::Database::Request.count.should == 0
86
88
  @database_inserter.aggregate(@incomplete_request)
87
- SpecFormat::Database::Request.count.should == 1
89
+ TestingFormat::Database::Request.count.should == 1
88
90
  end
89
91
 
90
92
  it "should insert records in all relevant line tables" do
91
93
  @database_inserter.aggregate(@completed_request)
92
- request = SpecFormat::Database::Request.first
94
+ request = TestingFormat::Database::Request.first
93
95
  request.should have(2).test_lines
94
96
  request.should have(1).first_lines
97
+ request.should have(1).eval_lines
95
98
  request.should have(1).last_lines
96
99
  end
97
100
 
98
101
  it "should log a warning in the warnings table" do
99
- SpecFormat::Database::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning'))
102
+ TestingFormat::Database::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning'))
100
103
  @database_inserter.warning(:test_warning, "Testing the warning system", 12)
101
104
  end
102
105
 
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Aggregator::Summarizer do
4
+
5
+ include RequestLogAnalyzer::Spec::Helper
6
+
7
+ before(:each) do
8
+ @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source, :output => mock_output)
9
+ @summarizer.prepare
10
+ end
11
+
12
+ it "not raise exception when creating a report after aggregating multiple requests" do
13
+ @summarizer.aggregate(request(:data => 'bluh1'))
14
+ @summarizer.aggregate(request(:data => 'bluh2'))
15
+
16
+ lambda { @summarizer.report(mock_output) }.should_not raise_error
17
+ end
18
+
19
+ it "not raise exception when creating a report after aggregating a single request" do
20
+ @summarizer.aggregate(request(:data => 'bluh1'))
21
+ lambda { @summarizer.report(mock_output) }.should_not raise_error
22
+ end
23
+
24
+ it "not raise exception when creating a report after aggregating no requests" do
25
+ lambda { @summarizer.report(mock_output) }.should_not raise_error
26
+ end
27
+
28
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Controller do
4
+
5
+ include RequestLogAnalyzer::Spec::Helper
6
+
7
+ it "should use a custom output generator correctly" do
8
+
9
+ mock_output = mock('RequestLogAnalyzer::Output::Base')
10
+ mock_output.stub!(:io).and_return(mock_io)
11
+ mock_output.should_receive(:header)
12
+ mock_output.should_receive(:footer)
13
+
14
+ controller = RequestLogAnalyzer::Controller.new(mock_source, :output => mock_output)
15
+
16
+ controller.run!
17
+ end
18
+
19
+ it "should call aggregators correctly when run" do
20
+ controller = RequestLogAnalyzer::Controller.new(mock_source, :output => mock_output)
21
+
22
+ mock_aggregator = mock('RequestLogAnalyzer::Aggregator::Base')
23
+ mock_aggregator.should_receive(:prepare).once.ordered
24
+ mock_aggregator.should_receive(:aggregate).with(an_instance_of(testing_format.request_class)).twice.ordered
25
+ mock_aggregator.should_receive(:finalize).once.ordered
26
+ mock_aggregator.should_receive(:report).once.ordered
27
+
28
+ controller.aggregators << mock_aggregator
29
+ controller.run!
30
+ end
31
+
32
+ it "should call filters when run" do
33
+ controller = RequestLogAnalyzer::Controller.new(mock_source, :output => mock_output)
34
+
35
+ mock_filter = mock('RequestLogAnalyzer::Filter::Base')
36
+ mock_filter.should_receive(:filter).twice.and_return(nil)
37
+ controller.should_receive(:aggregate_request).twice.and_return(nil)
38
+
39
+ controller.filters << mock_filter
40
+ controller.run!
41
+ end
42
+
43
+ end
@@ -1,12 +1,13 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
2
3
  require 'request_log_analyzer/log_processor'
3
4
 
4
5
  describe RequestLogAnalyzer::LogProcessor, 'stripping log files' do
5
6
 
6
- include RequestLogAnalyzerSpecHelper
7
+ include RequestLogAnalyzer::Spec::Helper
7
8
 
8
9
  before(:each) do
9
- @log_stripper = RequestLogAnalyzer::LogProcessor.new(spec_format, :strip, {})
10
+ @log_stripper = RequestLogAnalyzer::LogProcessor.new(testing_format, :strip, {})
10
11
  end
11
12
 
12
13
  it "should remove a junk line" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::FileFormat, :format_definition do
4
4
 
@@ -63,7 +63,18 @@ end
63
63
 
64
64
  describe RequestLogAnalyzer::FileFormat, :load do
65
65
 
66
- include RequestLogAnalyzerSpecHelper
66
+ include RequestLogAnalyzer::Spec::Helper
67
+
68
+ it "should return an instance of a FileFormat class" do
69
+ @file_format = RequestLogAnalyzer::FileFormat.load(TestingFormat)
70
+ @file_format.should be_kind_of(TestingFormat)
71
+ end
72
+
73
+
74
+ it "should return itself if it already is a FileFormat::Base instance" do
75
+ @file_format = RequestLogAnalyzer::FileFormat.load(testing_format)
76
+ @file_format.should be_kind_of(TestingFormat)
77
+ end
67
78
 
68
79
  it "should load a predefined file format from the /file_format dir" do
69
80
  @file_format = RequestLogAnalyzer::FileFormat.load(:rails)
@@ -71,8 +82,9 @@ describe RequestLogAnalyzer::FileFormat, :load do
71
82
  end
72
83
 
73
84
  it "should load a provided format file" do
74
- @file_format = RequestLogAnalyzer::FileFormat.load(format_file(:spec_format))
75
- @file_format.should be_kind_of(SpecFormat)
85
+ format_filename = File.dirname(__FILE__) + '/../../lib/testing_format.rb'
86
+ @file_format = RequestLogAnalyzer::FileFormat.load(format_filename)
87
+ @file_format.should be_kind_of(TestingFormat)
76
88
  end
77
89
 
78
90
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::LineDefinition, :parsing do
4
4
 
@@ -35,11 +35,11 @@ end
35
35
 
36
36
  describe RequestLogAnalyzer::LineDefinition, :converting do
37
37
 
38
- include RequestLogAnalyzerSpecHelper
38
+ include RequestLogAnalyzer::Spec::Helper
39
39
 
40
40
  before(:each) do
41
- @file_format = spec_format
42
- @request = @file_format.create_request
41
+ @file_format = testing_format
42
+ @request = @file_format.request
43
43
  end
44
44
 
45
45
  it "should convert captures to a hash of converted values" do
@@ -48,10 +48,17 @@ describe RequestLogAnalyzer::LineDefinition, :converting do
48
48
  end
49
49
 
50
50
  it "should convert captures to a hash" do
51
- hash = @file_format.line_definitions[:test].convert_captured_values(["willem", nil], @request)
52
- hash[:test_capture].should == 'Testing is willem'
51
+ hash = @file_format.line_definitions[:test].convert_captured_values(["great", nil], @request)
52
+ hash[:test_capture].should == 'Testing is great'
53
53
  hash[:duration].should be_nil
54
54
  end
55
+
56
+ it "should merge a hash capture into the line hash" do
57
+ hash = @file_format.line_definitions[:eval].convert_captured_values(["{ 'greating' => 'hello', 'what' => 'world'}"], @request)
58
+ hash[:evaluated].should == "{ 'greating' => 'hello', 'what' => 'world'}"
59
+ hash[:greating].should == 'hello'
60
+ hash[:what].should == 'world'
61
+ end
55
62
 
56
63
 
57
64
  end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Source::LogParser, :merb do
4
- include RequestLogAnalyzerSpecHelper
4
+ include RequestLogAnalyzer::Spec::Helper
5
5
 
6
6
  before(:each) do
7
7
  @log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:merb))
@@ -1,10 +1,11 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Source::LogParser, "Rails" do
4
- include RequestLogAnalyzerSpecHelper
4
+ include RequestLogAnalyzer::Spec::Helper
5
5
 
6
6
  before(:each) do
7
- @log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:rails))
7
+ @log_parser = RequestLogAnalyzer::Source::LogParser.new(
8
+ RequestLogAnalyzer::FileFormat.load(:rails), :parse_strategy => 'cautious')
8
9
  end
9
10
 
10
11
  it "should have a valid language definitions" do
@@ -66,27 +67,34 @@ describe RequestLogAnalyzer::Source::LogParser, "Rails" do
66
67
  end
67
68
 
68
69
  it "should detect unordered requests in the logs" do
70
+ # No valid request should be found in cautious mode
69
71
  @log_parser.should_not_receive(:handle_request)
70
72
  # the first Processing-line will not give a warning, but the next one will
71
73
  @log_parser.should_receive(:warn).with(:unclosed_request, anything).once
72
- # Both Completed ;ines will give a warning
74
+ # Both Completed lines will give a warning
73
75
  @log_parser.should_receive(:warn).with(:no_current_request, anything).twice
76
+
74
77
  @log_parser.parse_file(log_fixture(:rails_unordered))
75
78
  end
76
79
  end
77
80
 
78
- describe "RequestLogAnalyzer::FileFormat::RailsDevelopment - Rails with development details" do
79
- include RequestLogAnalyzerSpecHelper
81
+ describe RequestLogAnalyzer::FileFormat::RailsDevelopment, "Rails with development details" do
82
+ include RequestLogAnalyzer::Spec::Helper
80
83
 
81
84
  before(:each) do
82
85
  @file_format = RequestLogAnalyzer::FileFormat.load(:rails_development)
83
- @request = @file_format.create_request
86
+ @request = @file_format.request
84
87
  end
85
88
 
86
89
  it "should have a valid language definitions" do
87
90
  @file_format.should be_valid
88
91
  end
89
92
 
93
+ it "should have a different line definer than Rails" do
94
+ rails = RequestLogAnalyzer::FileFormat.load(:rails)
95
+ rails.class.line_definer.should_not == @file_format.class.line_definer
96
+ end
97
+
90
98
  it "should parse a rendered line" do
91
99
  info = @file_format.line_definitions[:rendered].match_for("Rendered layouts/_footer (2.9ms)", @request)
92
100
  info[:render_file].should == 'layouts/_footer'
@@ -97,25 +105,25 @@ describe "RequestLogAnalyzer::FileFormat::RailsDevelopment - Rails with developm
97
105
  info = @file_format.line_definitions[:query_executed].match_for(" User Load (0.4ms) SELECT * FROM `users` WHERE (`users`.`id` = 18205844) ", @request)
98
106
  info[:query_class].should == 'User'
99
107
  info[:query_duration].should == 0.0004
100
- info[:query_sql].should == 'SELECT * FROM `users` WHERE (`users`.`id` = 18205844)'
108
+ info[:query_sql].should == 'SELECT * FROM users WHERE (users.id = :int)'
101
109
  end
102
110
 
103
111
  it "should parse a query executed line without colors" do
104
112
  info = @file_format.line_definitions[:query_executed].match_for(" User Load (0.4ms) SELECT * FROM `users` WHERE (`users`.`id` = 18205844) ", @request)
105
113
  info[:query_class].should == 'User'
106
114
  info[:query_duration].should == 0.0004
107
- info[:query_sql].should == 'SELECT * FROM `users` WHERE (`users`.`id` = 18205844)'
115
+ info[:query_sql].should == 'SELECT * FROM users WHERE (users.id = :int)'
108
116
  end
109
117
 
110
118
  it "should parse a cached query line with colors" do
111
119
  info = @file_format.line_definitions[:query_cached].match_for(' CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 0) ', @request)
112
120
  info[:cached_duration].should == 0.0
113
- info[:cached_sql].should == 'SELECT * FROM `users` WHERE (`users`.`id` = 0)'
121
+ info[:cached_sql].should == 'SELECT * FROM users WHERE (users.id = :int)'
114
122
  end
115
123
 
116
124
  it "should parse a cached query line without colors" do
117
125
  info = @file_format.line_definitions[:query_cached].match_for(' CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 0) ', @request)
118
126
  info[:cached_duration].should == 0.0
119
- info[:cached_sql].should == 'SELECT * FROM `users` WHERE (`users`.`id` = 0)'
127
+ info[:cached_sql].should == 'SELECT * FROM users WHERE (users.id = :int)'
120
128
  end
121
129
  end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Filter::Anonymize, 'anonymize request' do
4
+ include RequestLogAnalyzer::Spec::Helper
5
+
6
+ before(:each) do
7
+ @filter = RequestLogAnalyzer::Filter::Anonymize.new(testing_format)
8
+ end
9
+
10
+ it "should anonimize ip" do
11
+ @filter.filter(request(:ip => '123.123.123.123'))[:ip].should_not eql('123.123.123.123')
12
+ end
13
+
14
+ it "should anonimize url" do
15
+ @filter.filter(request(:url => 'https://test.mysite.com/employees'))[:url].should eql('http://example.com/employees')
16
+ end
17
+
18
+ it "should fuzz durations" do
19
+ @filter.filter(request(:duration => 100))[:duration].should_not eql(100)
20
+ end
21
+
22
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Filter::Field, 'string in accept mode' do
4
+ include RequestLogAnalyzer::Spec::Helper
5
+
6
+ before(:each) do
7
+ @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :select)
8
+ end
9
+
10
+ it "should reject a request if the field value does not match" do
11
+ @filter.filter(request(:test => 'not test')).should be_nil
12
+ end
13
+
14
+ it "should reject a request if the field name does not match" do
15
+ @filter.filter(request(:testing => 'test')).should be_nil
16
+ end
17
+
18
+ it "should accept a request if the both name and value match" do
19
+ @filter.filter(request(:test => 'test')).should_not be_nil
20
+ end
21
+
22
+ it "should accept a request if the value is not the first value" do
23
+ @filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should_not be_nil
24
+ end
25
+ end
26
+
27
+ describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
28
+ include RequestLogAnalyzer::Spec::Helper
29
+
30
+ before(:each) do
31
+ @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :reject)
32
+ end
33
+
34
+ it "should accept a request if the field value does not match" do
35
+ @filter.filter(request(:test => 'not test')).should_not be_nil
36
+ end
37
+
38
+ it "should accept a request if the field name does not match" do
39
+ @filter.filter(request(:testing => 'test')).should_not be_nil
40
+ end
41
+
42
+ it "should reject a request if the both name and value match" do
43
+ @filter.filter(request(:test => 'test')).should be_nil
44
+ end
45
+
46
+ it "should reject a request if the value is not the first value" do
47
+ @filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should be_nil
48
+ end
49
+ end
50
+
51
+ describe RequestLogAnalyzer::Filter::Field, 'regexp in accept mode' do
52
+ include RequestLogAnalyzer::Spec::Helper
53
+
54
+ before(:each) do
55
+ @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => '/test/', :mode => :select)
56
+ end
57
+
58
+ it "should reject a request if the field value does not match" do
59
+ @filter.filter(request(:test => 'a working test')).should_not be_nil
60
+ end
61
+
62
+ it "should reject a request if the field name does not match" do
63
+ @filter.filter(request(:testing => 'test')).should be_nil
64
+ end
65
+
66
+ it "should accept a request if the value is not the first value" do
67
+ @filter.filter(request([{:test => 'ignore'}, {:test => 'testing 123'}])).should_not be_nil
68
+ end
69
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Filter::Timespan, 'both before and after' do
4
+ include RequestLogAnalyzer::Spec::Helper
5
+
6
+ before(:each) do
7
+ @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'), :before => DateTime.parse('2009-02-02'))
8
+ end
9
+
10
+ it "should reject a request before the after date" do
11
+ @filter.filter(request(:timestamp => 20081212000000)).should be_nil
12
+ end
13
+
14
+ it "should reject a request after the before date" do
15
+ @filter.filter(request(:timestamp => 20090303000000)).should be_nil
16
+ end
17
+
18
+ it "should accept a request between the after and before dates" do
19
+ @filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
20
+ end
21
+ end
22
+
23
+ describe RequestLogAnalyzer::Filter::Timespan, 'only before' do
24
+ include RequestLogAnalyzer::Spec::Helper
25
+
26
+ before(:each) do
27
+ @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :before => DateTime.parse('2009-02-02'))
28
+ end
29
+
30
+ it "should accept a request before the after date" do
31
+ @filter.filter(request(:timestamp => 20081212000000)).should_not be_nil
32
+ end
33
+
34
+ it "should reject a request after the before date" do
35
+ @filter.filter(request(:timestamp => 20090303000000)).should be_nil
36
+ end
37
+
38
+ it "should accept a request between the after and before dates" do
39
+ @filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
40
+ end
41
+ end
42
+
43
+ describe RequestLogAnalyzer::Filter::Timespan, 'only after' do
44
+ include RequestLogAnalyzer::Spec::Helper
45
+
46
+ before(:each) do
47
+ @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'))
48
+ end
49
+
50
+ it "should reject a request before the after date" do
51
+ @filter.filter(request(:timestamp => 20081212000000)).should be_nil
52
+ end
53
+
54
+ it "should accept a request after the before date" do
55
+ @filter.filter(request(:timestamp => 20090303000000)).should_not be_nil
56
+ end
57
+
58
+ it "should accept a request between the after and before dates" do
59
+ @filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
60
+ end
61
+ end
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Source::LogParser, :requests do
4
- include RequestLogAnalyzerSpecHelper
4
+ include RequestLogAnalyzer::Spec::Helper
5
5
 
6
6
  before(:each) do
7
- @log_parser = RequestLogAnalyzer::Source::LogParser.new(spec_format)
7
+ @log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
8
8
  end
9
9
 
10
10
  it "should have multiple line definitions" do
@@ -16,13 +16,13 @@ describe RequestLogAnalyzer::Source::LogParser, :requests do
16
16
  end
17
17
 
18
18
  it "should parse more lines than requests" do
19
- @log_parser.should_receive(:handle_request).with(an_instance_of(SpecFormat::Request)).twice
19
+ @log_parser.should_receive(:handle_request).with(an_instance_of(TestingFormat::Request)).twice
20
20
  @log_parser.parse_file(log_fixture(:test_language_combined))
21
21
  @log_parser.parsed_lines.should > 2
22
22
  end
23
23
 
24
24
  it "should parse requests spanned over multiple files" do
25
- @log_parser.should_receive(:handle_request).with(an_instance_of(SpecFormat::Request)).once
25
+ @log_parser.should_receive(:handle_request).with(an_instance_of(TestingFormat::Request)).once
26
26
  @log_parser.parse_files([log_fixture(:multiple_files_1), log_fixture(:multiple_files_2)])
27
27
  end
28
28
 
@@ -47,10 +47,10 @@ describe RequestLogAnalyzer::Source::LogParser, :requests do
47
47
  end
48
48
 
49
49
  describe RequestLogAnalyzer::Source::LogParser, :warnings do
50
- include RequestLogAnalyzerSpecHelper
50
+ include RequestLogAnalyzer::Spec::Helper
51
51
 
52
52
  before(:each) do
53
- @log_parser = RequestLogAnalyzer::Source::LogParser.new(spec_format)
53
+ @log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format, :parse_strategy => 'cautious')
54
54
  end
55
55
 
56
56
  it "should warn about teaser matching problems" do
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Request, :incomplete_request do
4
4
 
5
- include RequestLogAnalyzerSpecHelper
5
+ include RequestLogAnalyzer::Spec::Helper
6
6
 
7
7
  before(:each) do
8
- @incomplete_request = spec_format.create_request
8
+ @incomplete_request = testing_format.request
9
9
  @incomplete_request << { :line_type => :test, :lineno => 1, :test_capture => 'awesome!' }
10
10
  end
11
11
 
@@ -34,10 +34,10 @@ end
34
34
 
35
35
  describe RequestLogAnalyzer::Request, :completed_request do
36
36
 
37
- include RequestLogAnalyzerSpecHelper
37
+ include RequestLogAnalyzer::Spec::Helper
38
38
 
39
39
  before(:each) do
40
- @completed_request = spec_format.create_request
40
+ @completed_request = testing_format.request
41
41
  @completed_request << { :line_type => :first, :lineno => 1, :name => 'first line!' }
42
42
  @completed_request << { :line_type => :test, :lineno => 4, :test_capture => 'testing' }
43
43
  @completed_request << { :line_type => :test, :lineno => 7, :test_capture => 'testing some more' }