blitz 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- data/blitz.gemspec +2 -2
- data/lib/blitz.rb +1 -1
- data/lib/blitz/command/curl.rb +42 -26
- data/lib/blitz/curl.rb +1 -1
- data/lib/blitz/utils.rb +0 -1
- data/spec/blitz/command/curl_spec.rb +136 -0
- data/spec/spec_helper.rb +2 -1
- metadata +3 -3
data/blitz.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{blitz}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.22"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["pcapr"]
|
12
|
-
s.date = %q{2012-02-
|
12
|
+
s.date = %q{2012-02-17}
|
13
13
|
s.default_executable = %q{blitz}
|
14
14
|
s.description = %q{Make load and performance testing a fun sport}
|
15
15
|
s.email = %q{support@blitz.io}
|
data/lib/blitz.rb
CHANGED
data/lib/blitz/command/curl.rb
CHANGED
@@ -78,6 +78,35 @@ class Curl < Command # :nodoc:
|
|
78
78
|
rtt = ("%.2f" % rtt) + ' sec';
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
def print_sprint_content content
|
83
|
+
if not content.empty?
|
84
|
+
if /^[[:print:]]+$/ =~ content
|
85
|
+
puts content
|
86
|
+
else
|
87
|
+
puts Hexy.new(content).to_s
|
88
|
+
end
|
89
|
+
puts
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def print_sprint_header obj, path, symbol, mode
|
94
|
+
if path == "-"
|
95
|
+
puts symbol + obj.line
|
96
|
+
obj.headers.each_pair { |k, v| puts "#{symbol}#{k}: #{v}\r\n" }
|
97
|
+
puts
|
98
|
+
else
|
99
|
+
begin
|
100
|
+
File.open(path, mode) do |myfile|
|
101
|
+
myfile.puts ""
|
102
|
+
myfile.puts obj.line
|
103
|
+
obj.headers.each_pair { |k, v| myfile.puts("#{k}: #{v}") }
|
104
|
+
end
|
105
|
+
rescue Exception => e
|
106
|
+
msg "#{red(e.message)}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
81
110
|
|
82
111
|
def print_sprint_result args, result
|
83
112
|
if result.respond_to? :duration
|
@@ -88,34 +117,21 @@ class Curl < Command # :nodoc:
|
|
88
117
|
|
89
118
|
result.steps.each do |step|
|
90
119
|
req, res = step.request, step.response
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
content = req.content
|
97
|
-
if not content.empty?
|
98
|
-
if /^[[:print:]]+$/ =~ content
|
99
|
-
puts content
|
100
|
-
else
|
101
|
-
puts Hexy.new(content).to_s
|
102
|
-
end
|
103
|
-
puts
|
104
|
-
end
|
105
|
-
|
120
|
+
dump_header = args['dump-header']
|
121
|
+
verbose = args['verbose']
|
122
|
+
if dump_header and verbose
|
123
|
+
print_sprint_header req, dump_header, "> ", 'w'
|
124
|
+
print_sprint_content req.content
|
106
125
|
if res
|
107
|
-
|
108
|
-
res.
|
109
|
-
puts
|
110
|
-
content = res.content
|
111
|
-
if not content.empty?
|
112
|
-
if /^[[:print:]]+$/ =~ content
|
113
|
-
puts content
|
114
|
-
else
|
115
|
-
puts Hexy.new(content).to_s
|
116
|
-
end
|
117
|
-
end
|
126
|
+
print_sprint_header res, dump_header, "< ", 'a'
|
127
|
+
print_sprint_content res.content
|
118
128
|
end
|
129
|
+
elsif dump_header.nil? and verbose
|
130
|
+
print_sprint_content req.content
|
131
|
+
print_sprint_content res.content if res
|
132
|
+
elsif dump_header and verbose.nil?
|
133
|
+
print_sprint_header req, dump_header, "> ", 'w'
|
134
|
+
print_sprint_header res, dump_header, "< ", 'a' if res
|
119
135
|
else
|
120
136
|
puts "> " + req.method + ' ' + req.url
|
121
137
|
if res
|
data/lib/blitz/curl.rb
CHANGED
data/lib/blitz/utils.rb
CHANGED
@@ -1,4 +1,140 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Blitz::Command::Curl do
|
4
|
+
|
5
|
+
let(:sprint_data) {
|
6
|
+
{
|
7
|
+
'line'=>"GET / HTTP/1.1",
|
8
|
+
'method'=>"GET",
|
9
|
+
'url'=>"www.example.com",
|
10
|
+
'content'=>"",
|
11
|
+
'status'=>200,
|
12
|
+
'message'=>"OK",
|
13
|
+
'headers'=> {
|
14
|
+
"User-Agent"=>"blitz.io; 5f691b@11.22.33.250",
|
15
|
+
"Host"=>"blitz.io",
|
16
|
+
"X-Powered-By"=>"blitz.io",
|
17
|
+
"X-User-ID"=>"5f6938a60e",
|
18
|
+
"X-User-IP"=>"44.55.66.250"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
def mocked_sprint_request
|
24
|
+
Blitz::Curl::Sprint::Request.new(sprint_data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def mocked_sprint_args
|
28
|
+
{
|
29
|
+
"steps"=>[{"url"=>"http://blitz.io"}],
|
30
|
+
"region"=>"california",
|
31
|
+
"dump-header"=>"/mocked/path/head.txt",
|
32
|
+
"verbose"=>true
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def mocked_sprint
|
37
|
+
sprint = {
|
38
|
+
'result' => {
|
39
|
+
'region'=>"california",
|
40
|
+
'duration'=> 0.39443,
|
41
|
+
'steps'=>[
|
42
|
+
'connect'=>0.117957,
|
43
|
+
'duration'=>0.394431,
|
44
|
+
'request' => sprint_data,
|
45
|
+
'response' => sprint_data
|
46
|
+
]
|
47
|
+
}
|
48
|
+
}
|
49
|
+
Blitz::Curl::Sprint::Result.new(sprint)
|
50
|
+
end
|
51
|
+
|
52
|
+
context "#print_sprint_header" do
|
53
|
+
def check_print_sprint_header path="/mocked/path/head.txt"
|
54
|
+
myfile = StringIO.new
|
55
|
+
request = mocked_sprint_request
|
56
|
+
symbol = "> "
|
57
|
+
mode = 'w'
|
58
|
+
obj = Blitz::Command::Curl.new
|
59
|
+
yield(obj, path, mode)
|
60
|
+
obj.send(:print_sprint_header, request, path, symbol, mode)
|
61
|
+
end
|
62
|
+
it "should prints header to console when path is '-'" do
|
63
|
+
check_print_sprint_header("-") {|obj, path, mode|
|
64
|
+
obj.should_receive(:puts).with("> GET / HTTP/1.1")
|
65
|
+
obj.should_receive(:puts).with("> User-Agent: blitz.io; 5f691b@11.22.33.250\r\n")
|
66
|
+
obj.should_receive(:puts).with("> Host: blitz.io\r\n")
|
67
|
+
obj.should_receive(:puts).with("> X-Powered-By: blitz.io\r\n")
|
68
|
+
obj.should_receive(:puts).with("> X-User-ID: 5f6938a60e\r\n")
|
69
|
+
obj.should_receive(:puts).with("> X-User-IP: 44.55.66.250\r\n")
|
70
|
+
obj.should_receive(:puts).with()
|
71
|
+
}
|
72
|
+
end
|
73
|
+
it "should warn user if it can not open the file" do
|
74
|
+
check_print_sprint_header() {|obj, path, mode|
|
75
|
+
File.should_receive(:open).with(path, mode).and_raise("No such file or directory - #{path}")
|
76
|
+
obj.should_receive(:puts).with("\e[31mNo such file or directory - #{path}\e[0m")
|
77
|
+
}
|
78
|
+
end
|
79
|
+
it "should print request headers to file" do
|
80
|
+
check_print_sprint_header() {|obj, path, mode|
|
81
|
+
file = mock('file')
|
82
|
+
File.should_receive(:open).with(path, mode).and_yield(file)
|
83
|
+
file.should_receive(:puts).with("")
|
84
|
+
file.should_receive(:puts).with("GET / HTTP/1.1")
|
85
|
+
file.should_receive(:puts).with("User-Agent: blitz.io; 5f691b@11.22.33.250")
|
86
|
+
file.should_receive(:puts).with("Host: blitz.io")
|
87
|
+
file.should_receive(:puts).with("X-Powered-By: blitz.io")
|
88
|
+
file.should_receive(:puts).with("X-User-ID: 5f6938a60e")
|
89
|
+
file.should_receive(:puts).with("X-User-IP: 44.55.66.250")
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "#print_sprint_result" do
|
95
|
+
def check_print_sprint_result args
|
96
|
+
result = mocked_sprint
|
97
|
+
obj = Blitz::Command::Curl.new
|
98
|
+
yield(obj, result)
|
99
|
+
obj.send(:print_sprint_result, args, result)
|
100
|
+
end
|
101
|
+
it "should not dump-header and verbose when they are not available" do
|
102
|
+
args = mocked_sprint_args
|
103
|
+
args.delete "verbose"
|
104
|
+
args.delete "dump-header"
|
105
|
+
check_print_sprint_result(args){|obj, result|
|
106
|
+
obj.should_receive(:puts).with("Transaction time \e[32m394 ms\e[0m")
|
107
|
+
obj.should_receive(:puts).with()
|
108
|
+
obj.should_receive(:puts).with("> GET www.example.com")
|
109
|
+
obj.should_receive(:puts).with("< 200 OK in \e[32m394 ms\e[0m")
|
110
|
+
obj.should_receive(:puts).with()
|
111
|
+
}
|
112
|
+
end
|
113
|
+
it "should dump-header and verbose when both are available" do
|
114
|
+
check_print_sprint_result(mocked_sprint_args){|obj, result|
|
115
|
+
obj.should_receive(:print_sprint_header).twice.and_return(true)
|
116
|
+
obj.should_receive(:print_sprint_content).twice.and_return(true)
|
117
|
+
result.should_receive(:respond_to?).with(:duration).and_return(false)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
it "should only do verbose when dump-header is not available" do
|
121
|
+
args = mocked_sprint_args
|
122
|
+
args.delete "dump-header"
|
123
|
+
check_print_sprint_result(args){|obj, result|
|
124
|
+
obj.should_not_receive(:print_sprint_header)
|
125
|
+
obj.should_receive(:print_sprint_content).twice.and_return(true)
|
126
|
+
result.should_receive(:respond_to?).with(:duration).and_return(false)
|
127
|
+
}
|
128
|
+
end
|
129
|
+
it "should only do dump-header when verbose is not available" do
|
130
|
+
args = mocked_sprint_args
|
131
|
+
args.delete "verbose"
|
132
|
+
check_print_sprint_result(args){|obj, result|
|
133
|
+
obj.should_receive(:print_sprint_header).twice.and_return(true)
|
134
|
+
obj.should_not_receive(:print_sprint_content)
|
135
|
+
result.should_receive(:respond_to?).with(:duration).and_return(false)
|
136
|
+
}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
4
140
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: blitz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.22
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- pcapr
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-17 00:00:00 -08:00
|
14
14
|
default_executable: blitz
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -171,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
171
|
requirements:
|
172
172
|
- - ">="
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
hash:
|
174
|
+
hash: -600337631
|
175
175
|
segments:
|
176
176
|
- 0
|
177
177
|
version: "0"
|