Permalink
Browse files

Add feature exercising range requests

Change-Id: I433aafe0dea3d53c7a9eef54a4e22a878105107f
  • Loading branch information...
1 parent 6343d76 commit d0bd45fd1c55bc0683e52af3623b76500fec1b83 mpage committed May 30, 2012
Showing with 63 additions and 4 deletions.
  1. +4 −4 Gemfile.lock
  2. +18 −0 features/range_requests.feature
  3. +41 −0 features/step_definitions/range_requests_steps.rb
View
@@ -57,9 +57,9 @@ GEM
rspec (1.3.0)
rubyzip (0.9.8)
sinatra (1.3.2)
- rack (>= 1.3.6, ~> 1.3)
+ rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
- tilt (>= 1.3.3, ~> 1.3)
+ tilt (~> 1.3, >= 1.3.3)
term-ansicolor (1.0.7)
terminal-table (1.4.5)
thin (1.3.1)
@@ -71,8 +71,8 @@ GEM
vmc (0.3.17)
addressable (~> 2.2.6)
interact (~> 0.4.0)
- json_pure (< 1.7.0, >= 1.5.1)
- rest-client (< 1.7.0, >= 1.6.1)
+ json_pure (>= 1.5.1, < 1.7.0)
+ rest-client (>= 1.6.1, < 1.7.0)
rubyzip (~> 0.9.4)
terminal-table (~> 1.4.2)
uuidtools (~> 2.1.0)
@@ -0,0 +1,18 @@
+Feature: Range request support
+
+ As a user of Cloud Foundry
+ I want to be able to retrieve portions of my files
+
+ Background: Range request support
+ Given I have registered and logged in
+ Given I have deployed my application named simple_app
+
+ Scenario: Request with a partially specified range
+ When I request a file named foo.rb with the range '-10'
+ Then I should get back the final 10 bytes of the file.
+ When I request a file named foo.rb with the range '10-'
+ Then I should get back the final 222 bytes of the file.
+
+ Scenario: Request with a fully specified range
+ When I request a file named foo.rb with the range '10-20'
+ Then I should get back bytes 10-20 of the file.
@@ -0,0 +1,41 @@
+require 'rest-client'
+
+When /^I request a file named ([^ ]+) with the range '([^']+)'$/ do |fn, range|
+ file_path = File.join(@root_dir, @config[@app]["path"], fn)
+ @file_contents = File.read(file_path)
+
+ path = VMC::Client.path(VMC::APPS_PATH, get_app_name(@app),
+ "instances", "0", "files", "app", fn)
+ url = "#{@client.target}/#{path}"
+
+ hdrs = {
+ "AUTHORIZATION" => @client.auth_token,
+ "Range" => "bytes=#{range}",
+ }
+
+ resp = RestClient.get(url, hdrs)
+
+ resp.should_not == nil
+ resp.code.should == 206
+ resp.body.should_not == nil
+
+ @body = resp.body
+end
+
+Then /^I should get back the final (\d+) bytes of the file\.$/ do |num_bytes|
+ num_bytes = num_bytes.to_i
+
+ @body.should == @file_contents.slice(@file_contents.size - num_bytes,
+ num_bytes)
+end
+
+Then /^I should get back bytes (\d+)-(\d+) of the file\.$/ do |start, fin|
+ start = start.to_i
+ fin = fin.to_i
+
+ num_bytes = fin - start + 1
+
+ @body.should == @file_contents.slice(start, num_bytes)
+end
+
+

0 comments on commit d0bd45f

Please sign in to comment.