blitz 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,6 +8,8 @@ gem "rest-client", "~> 1.6.1"
8
8
  gem "json", "~> 1.5.1"
9
9
  gem "json_pure", "~> 1.5.1"
10
10
  gem "hexy", "~> 0.1.1"
11
+ gem 'rspec', '2.6.0'
12
+ gem 'rspec-core', '2.6.4'
11
13
 
12
14
  # Add dependencies to develop your gem here.
13
15
  # Include everything needed to run rake, tests, features, etc.
@@ -15,3 +17,4 @@ group :development do
15
17
  gem "bundler", "~> 1.0.0"
16
18
  gem "jeweler", "~> 1.5.1"
17
19
  end
20
+
@@ -5,6 +5,7 @@ GEM
5
5
  json (>= 1.4.6)
6
6
  mime-types (>= 1.15)
7
7
  rest-client (>= 1.5.1)
8
+ diff-lcs (1.1.2)
8
9
  git (1.2.5)
9
10
  hexy (0.1.1)
10
11
  jeweler (1.5.1)
@@ -17,6 +18,14 @@ GEM
17
18
  rake (0.8.7)
18
19
  rest-client (1.6.1)
19
20
  mime-types (>= 1.16)
21
+ rspec (2.6.0)
22
+ rspec-core (~> 2.6.0)
23
+ rspec-expectations (~> 2.6.0)
24
+ rspec-mocks (~> 2.6.0)
25
+ rspec-core (2.6.4)
26
+ rspec-expectations (2.6.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.6.0)
20
29
 
21
30
  PLATFORMS
22
31
  ruby
@@ -29,3 +38,5 @@ DEPENDENCIES
29
38
  json (~> 1.5.1)
30
39
  json_pure (~> 1.5.1)
31
40
  rest-client (~> 1.6.1)
41
+ rspec (= 2.6.0)
42
+ rspec-core (= 2.6.4)
data/Rakefile CHANGED
@@ -39,6 +39,13 @@ Rake::TestTask.new(:test) do |test|
39
39
  test.verbose = true
40
40
  end
41
41
 
42
+ desc "Run all the specs"
43
+ task :spec do
44
+ require 'rspec/core'
45
+ require 'blitz'
46
+ RSpec::Core::Runner.run [ *Dir.glob('spec/**/*.rb') ]
47
+ end
48
+
42
49
  task :default => :test
43
50
 
44
51
  require 'rake/rdoctask'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blitz}
8
- s.version = "0.1.10"
8
+ s.version = "0.1.11"
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{2011-07-15}
12
+ s.date = %q{2011-07-19}
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}
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/blitz/curl/rush.rb",
39
39
  "lib/blitz/curl/sprint.rb",
40
40
  "lib/blitz/helper.rb",
41
+ "spec/command/curl_spec.rb",
41
42
  "test/helper.rb",
42
43
  "test/test_blitz.rb"
43
44
  ]
@@ -47,6 +48,7 @@ Gem::Specification.new do |s|
47
48
  s.rubygems_version = %q{1.6.2}
48
49
  s.summary = %q{Make load and performance testing a fun sport}
49
50
  s.test_files = [
51
+ "spec/command/curl_spec.rb",
50
52
  "test/helper.rb",
51
53
  "test/test_blitz.rb"
52
54
  ]
@@ -60,6 +62,8 @@ Gem::Specification.new do |s|
60
62
  s.add_runtime_dependency(%q<json>, ["~> 1.5.1"])
61
63
  s.add_runtime_dependency(%q<json_pure>, ["~> 1.5.1"])
62
64
  s.add_runtime_dependency(%q<hexy>, ["~> 0.1.1"])
65
+ s.add_runtime_dependency(%q<rspec>, ["= 2.6.0"])
66
+ s.add_runtime_dependency(%q<rspec-core>, ["= 2.6.4"])
63
67
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
68
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
65
69
  else
@@ -68,6 +72,8 @@ Gem::Specification.new do |s|
68
72
  s.add_dependency(%q<json>, ["~> 1.5.1"])
69
73
  s.add_dependency(%q<json_pure>, ["~> 1.5.1"])
70
74
  s.add_dependency(%q<hexy>, ["~> 0.1.1"])
75
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
76
+ s.add_dependency(%q<rspec-core>, ["= 2.6.4"])
71
77
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
78
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
73
79
  end
@@ -77,6 +83,8 @@ Gem::Specification.new do |s|
77
83
  s.add_dependency(%q<json>, ["~> 1.5.1"])
78
84
  s.add_dependency(%q<json_pure>, ["~> 1.5.1"])
79
85
  s.add_dependency(%q<hexy>, ["~> 0.1.1"])
86
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
87
+ s.add_dependency(%q<rspec-core>, ["= 2.6.4"])
80
88
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
89
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
82
90
  end
@@ -5,7 +5,7 @@ require 'pp'
5
5
 
6
6
  class Blitz # :nodoc:
7
7
  require 'blitz/helper'
8
- Version = "0.1.10"
8
+ Version = "0.1.11"
9
9
 
10
10
  extend Blitz::Helper
11
11
 
@@ -355,7 +355,9 @@ class Curl < Command # :nodoc:
355
355
 
356
356
  if not hash['help']
357
357
  url = argv.shift
358
- assert_not_nil(url, 'no URL specified!')
358
+ if not url
359
+ raise ArgumentError, "no URL specified!"
360
+ end
359
361
  hash['url'] = url
360
362
  end
361
363
 
@@ -0,0 +1,232 @@
1
+ describe "arg parsing" do
2
+
3
+ TEST_URL = "http://foo.com"
4
+ VAR = 'foo'
5
+ TEST_VAR_URL = 'http://foo.com?var=#{foo}'
6
+ MIN = 10
7
+ MAX = 30
8
+ # because of 1.8.7 and 1.9.2 differences, maintain both LIST and LIST_AS_STRING constants
9
+ LIST = [ 'a', 'b', 'c', '1', '2', '3']
10
+ LIST_AS_STRING = "[a,b,c,1,2,3]"
11
+ COUNT = 60
12
+ COUNT_DEFAULT = 1000
13
+ DURATION = 100
14
+ REGION = 'california'
15
+
16
+ curl = ::Blitz::Command::Curl.new
17
+ describe "basic args" do
18
+
19
+ describe "pattern and region" do
20
+ @args = {
21
+ "expanded parameters" => [ '--pattern', '1-250:60', "--region", "#{REGION}", "#{TEST_URL}" ],
22
+ "short parameters" => [ '-p', '1-250:60', "--region", "#{REGION}", "#{TEST_URL}" ]
23
+ }
24
+
25
+ @args.each do |name, argv|
26
+ parsed_args = curl.__send__ :parse_cli, argv
27
+
28
+ it "should return a hash from the method when sending #{name}" do
29
+ parsed_args.should be_a(Hash)
30
+ end
31
+
32
+ it "should populate the URL into the url key when sending #{name}" do
33
+ parsed_args['url'].should be_a(String)
34
+ parsed_args['url'].should == TEST_URL
35
+ end
36
+
37
+ it "should put --pattern arguments in the correct structure when sending #{name}" do
38
+ parsed_args['pattern'].should be_a(Hash)
39
+ parsed_args['pattern']['iterations'].should be_equal 1
40
+ parsed_args['pattern']['intervals'].should be_a(Array)
41
+ parsed_args['pattern']['intervals'][0].should be_a(Hash)
42
+ parsed_args['pattern']['intervals'][0]['start'].should be_equal 1
43
+ parsed_args['pattern']['intervals'][0]['end'].should be_equal 250
44
+ parsed_args['pattern']['intervals'][0]['duration'].should be_equal 60
45
+ end
46
+
47
+ it "should allow a specific region to be passed when sending #{name}" do
48
+ parsed_args['region'].should be_a(String)
49
+ parsed_args['region'].should == REGION
50
+ end
51
+ end
52
+ end
53
+
54
+ @command_args = [
55
+ { :short => '-A', :long => '--user-agent', :params => '"TEST STRING"', :blitz_key => 'user-agent' },
56
+ { :short => '-b', :long => '--cookie', :params => 'name=somecookie' },
57
+ { :short => '-d', :long => '--data', :params => '"data for post"'},
58
+ { :short => '-D', :long => '--dump-header', :params => '"somefile.out"' },
59
+ { :short => '-e', :long => '--referer', :params => '"http://google.com"' },
60
+ { :short => '-H', :long => '--header', :params => 'some_header' },
61
+ { :short => '-s', :long => '--status', :params => '500' },
62
+ { :short => '-T', :long => '--timeout', :params => '750' },
63
+ { :short => '-u', :long => '--user', :params => 'foo:bar' },
64
+ { :short => '-X', :long => '--request', :params => 'GET' },
65
+ { :short => '-V', :long => '--verbose' },
66
+ { :short => '-1', :long => '--tlsv1' },
67
+ { :short => '-2', :long => '--sslv2' },
68
+ { :short => '-3', :long => '--sslv3' },
69
+ ]
70
+ @command_args.each do |test|
71
+ test_name = /--(.*)/.match(test[:long])[1]
72
+ describe "#{test_name}" do
73
+ [ :short, :long ].each do |flag|
74
+ argv = []
75
+ argv << test[flag]
76
+ argv << test[:params] if test[:params]
77
+ argv << "#{TEST_URL}"
78
+ it "#{test[flag]} should not raise an error and populate the hash properly" do
79
+ lambda { curl.__send__ :parse_cli, argv.dup }.should_not raise_error
80
+ parsed_args = curl.__send__ :parse_cli, argv
81
+ if test[:blitz_key]
82
+ parsed_args[ test[:blitz_key] ].should == test[:params]
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "help" do
91
+ @args = {
92
+ "expanded parameters" => [ '--help' ],
93
+ "short parameters" => [ '-h' ]
94
+ }
95
+ @args.each do |name, argv|
96
+ it "should return boolean help flag in hash for #{name}" do
97
+ parsed_args = curl.__send__ :parse_cli, argv
98
+ parsed_args.should be_a(Hash)
99
+ parsed_args['help'].should be_true
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "Usage errors" do
105
+ describe "no arguments" do
106
+ it "should throw an error when no arguments are given" do
107
+ lambda { curl.__send__ :parse_cli }.should raise_error(ArgumentError, /wrong number of arg/)
108
+ end
109
+ end
110
+ describe "no URL" do
111
+ @args = {
112
+ "expanded parameters" => [ '--pattern', '1-250:60', "--variable:#{VAR}", "udid", "--region", "#{REGION}" ],
113
+ "short parameters" => [ '-p', '1-250:60', "-v:#{VAR}", "u", "-r", "#{REGION}" ]
114
+ }
115
+ @args.each do |name, argv|
116
+ it "should throw an error when no URL is given for #{name}" do
117
+ lambda { curl.__send__ :parse_cli, argv}.should raise_error(ArgumentError, /URL/)
118
+ end
119
+ end
120
+ end
121
+ describe "bad arguments" do
122
+ @args = {
123
+ "double dash on short param" => [ '--p', '1-250:60', "--variable:#{VAR}", "udid", "--region", "#{REGION}", "#{TEST_URL}" ],
124
+ "single dash on long param" => [ '-pattern', '1-250:60', "-v:#{VAR}", "u", "-r", "#{REGION}", "#{TEST_URL}" ],
125
+ "unsupported option, short format" => [ '-z', "#{TEST_URL}" ],
126
+ "unsupported option, long format" => [ '--foobar', "#{TEST_URL}" ]
127
+ }
128
+ @args.each do |name, argv|
129
+ it "should throw an error when bad arguments are passed for #{name}" do
130
+ lambda { curl.__send__ :parse_cli, argv}.should raise_error(ArgumentError, /Unknown option/)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "variable support" do
137
+ describe "number and alpha" do
138
+ @args = {
139
+ "number, expanded parameters, no values given" =>
140
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "number", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
141
+ "number, short parameters, no values given" =>
142
+ [ '-p', '1-250:60', "-v:#{VAR}", "n", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
143
+ "number, expanded parameters, no count given" =>
144
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "number[#{MIN},#{MAX}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
145
+ "number, short parameters, no count given" =>
146
+ [ '-p', '1-250:60', "-v:#{VAR}", "n[#{MIN},#{MAX}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
147
+ "number, expanded parameters, count given" =>
148
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "number[#{MIN},#{MAX},#{COUNT}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
149
+ "number, short parameters, count given" =>
150
+ [ '-p', '1-250:60', "-v:#{VAR}", "n[#{MIN},#{MAX},#{COUNT}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
151
+ "alpha, expanded parameters, no values given" =>
152
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "alpha", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
153
+ "alpha, short parameters, no values given" =>
154
+ [ '-p', '1-250:60', "-v:#{VAR}", "a", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
155
+ "alpha, expanded parameters, no count given" =>
156
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "alpha[#{MIN},#{MAX}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
157
+ "alpha, short parameters, no count given" =>
158
+ [ '-p', '1-250:60', "-v:#{VAR}", "a[#{MIN},#{MAX}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
159
+ "alpha, expanded parameters, count given" =>
160
+ [ '--pattern', '1-250:60', "--variable:#{VAR}", "alpha[#{MIN},#{MAX},#{COUNT}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ],
161
+ "alpha, short parameters, count given" =>
162
+ [ '-p', '1-250:60', "-v:#{VAR}", "a[#{MIN},#{MAX},#{COUNT}]", "--region", "#{REGION}", "#{TEST_VAR_URL}" ]
163
+ }
164
+
165
+ @args.each do |name, argv|
166
+ parsed_args = curl.__send__ :parse_cli, argv
167
+ it "should work with #{name}" do
168
+ parsed_args['variables'].should be_a(Hash)
169
+ parsed_args['variables'][VAR].should be_a(Hash)
170
+
171
+ if name.match(/^number/)
172
+ parsed_args['variables'][VAR]['type'].should == "number"
173
+ elsif name.match(/^alpha/)
174
+ parsed_args['variables'][VAR]['type'].should == "alpha"
175
+ end
176
+
177
+ if name.match(/no values given/)
178
+ parsed_args['variables'][VAR]['min'].should be_nil
179
+ parsed_args['variables'][VAR]['max'].should be_nil
180
+ parsed_args['variables'][VAR]['count'].should be_nil
181
+ elsif name.match(/no count given/)
182
+ parsed_args['variables'][VAR]['min'].should be_an(Integer)
183
+ parsed_args['variables'][VAR]['min'].should == MIN
184
+ parsed_args['variables'][VAR]['max'].should be_an(Integer)
185
+ parsed_args['variables'][VAR]['max'].should == MAX
186
+ parsed_args['variables'][VAR]['count'].should be_an(Integer)
187
+ parsed_args['variables'][VAR]['count'].should == COUNT_DEFAULT
188
+ else
189
+ parsed_args['variables'][VAR]['min'].should be_an(Integer)
190
+ parsed_args['variables'][VAR]['min'].should == MIN
191
+ parsed_args['variables'][VAR]['max'].should be_an(Integer)
192
+ parsed_args['variables'][VAR]['max'].should == MAX
193
+ parsed_args['variables'][VAR]['count'].should be_an(Integer)
194
+ parsed_args['variables'][VAR]['count'].should == COUNT
195
+ end
196
+
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "list parameter" do
202
+ @args = {
203
+ "expanded parameters" => [ '--pattern', '1-250:60', "--variable:#{VAR}", "list#{LIST_AS_STRING}", "--region", "#{REGION}", "#{TEST_URL}" ],
204
+ "short parameters" => [ '-p', '1-250:60', "-v:#{VAR}", "#{LIST_AS_STRING}", "-r", "#{REGION}", "#{TEST_URL}" ]
205
+ }
206
+ @args.each do |name, argv|
207
+ it "should allow lists to be sent as a variable type for #{name}" do
208
+ parsed_args = curl.__send__ :parse_cli, argv
209
+ parsed_args['variables'][VAR].should be_a(Hash)
210
+ parsed_args['variables'][VAR]['type'].should == 'list'
211
+ parsed_args['variables'][VAR]['entries'].should be_an(Array)
212
+ parsed_args['variables'][VAR]['entries'].should == LIST
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "udid parameter" do
218
+ @args = {
219
+ "expanded parameters" => [ '--pattern', '1-250:60', "--variable:#{VAR}", "udid", "--region", "#{REGION}", "#{TEST_URL}" ],
220
+ "short parameters" => [ '-p', '1-250:60', "-v:#{VAR}", "u", "-r", "#{REGION}", "#{TEST_URL}" ]
221
+ }
222
+ @args.each do |name, argv|
223
+ parsed_args = curl.__send__ :parse_cli, argv
224
+ it "should allow udid to be sent as a variable type" do
225
+ parsed_args['variables'][VAR].should be_a(Hash)
226
+ parsed_args['variables'][VAR]['type'].should == 'udid'
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
232
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: blitz
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.10
5
+ version: 0.1.11
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: 2011-07-15 00:00:00 -07:00
13
+ date: 2011-07-19 00:00:00 -07:00
14
14
  default_executable: blitz
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -69,8 +69,30 @@ dependencies:
69
69
  prerelease: false
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: bundler
72
+ name: rspec
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.6.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec-core
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - "="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: &id008 !ruby/object:Gem::Requirement
74
96
  none: false
75
97
  requirements:
76
98
  - - ~>
@@ -78,10 +100,10 @@ dependencies:
78
100
  version: 1.0.0
79
101
  type: :development
80
102
  prerelease: false
81
- version_requirements: *id006
103
+ version_requirements: *id008
82
104
  - !ruby/object:Gem::Dependency
83
105
  name: jeweler
84
- requirement: &id007 !ruby/object:Gem::Requirement
106
+ requirement: &id009 !ruby/object:Gem::Requirement
85
107
  none: false
86
108
  requirements:
87
109
  - - ~>
@@ -89,7 +111,7 @@ dependencies:
89
111
  version: 1.5.1
90
112
  type: :development
91
113
  prerelease: false
92
- version_requirements: *id007
114
+ version_requirements: *id009
93
115
  description: Make load and performance testing a fun sport
94
116
  email: support@blitz.io
95
117
  executables:
@@ -119,6 +141,7 @@ files:
119
141
  - lib/blitz/curl/rush.rb
120
142
  - lib/blitz/curl/sprint.rb
121
143
  - lib/blitz/helper.rb
144
+ - spec/command/curl_spec.rb
122
145
  - test/helper.rb
123
146
  - test/test_blitz.rb
124
147
  has_rdoc: true
@@ -135,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
158
  requirements:
136
159
  - - ">="
137
160
  - !ruby/object:Gem::Version
138
- hash: -193852493
161
+ hash: 109260913
139
162
  segments:
140
163
  - 0
141
164
  version: "0"
@@ -153,5 +176,6 @@ signing_key:
153
176
  specification_version: 3
154
177
  summary: Make load and performance testing a fun sport
155
178
  test_files:
179
+ - spec/command/curl_spec.rb
156
180
  - test/helper.rb
157
181
  - test/test_blitz.rb