forked from threez/test-http-clients
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented most of the tests and added main test case test.rb
- Loading branch information
Vincent Landgraf
committed
Jan 31, 2011
1 parent
30f2c28
commit 7416856
Showing
13 changed files
with
82 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rubygems' | ||
require 'uri' | ||
require 'benchmark' | ||
require 'yajl' | ||
require 'yajl/json_gem' | ||
|
||
ITERATIONS = 1000 | ||
TESTS = [] | ||
|
||
def test_http(name, &block) | ||
TESTS << [name, block] | ||
end | ||
|
||
URL = URI.parse("http://localhost/~vincentlandgraf/test.json") | ||
|
||
dir = File.dirname(__FILE__) | ||
|
||
Dir[File.join(dir, "test_*.rb")].each do |file| | ||
require file | ||
end | ||
|
||
at_exit do | ||
Benchmark.bm(20) do |x| | ||
for name, block in TESTS do | ||
x.report("testing #{name}") do | ||
ITERATIONS.times(&block) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "curb" | ||
|
||
c = Curl::Easy.new | ||
test_http("curb") do | ||
c.url = URL.to_s | ||
c.headers["X-Test"] = "test" | ||
c.perform | ||
data = JSON.parse(c.body_str) | ||
raise Exception.new unless data.first["number"] != 123123 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test_http("curl") do | ||
header = {"X-Test" => "test"} | ||
header_str = "" | ||
header.each { |key, value| header_str += "-H \"#{key}: #{value}\" "} | ||
response = `curl #{header_str} -s #{URL.to_s.inspect}` | ||
data = JSON.parse(response) | ||
raise Exception.new unless data.first["number"] != 123123 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# require 'em-http' | ||
# | ||
# evm_count = ITERATIONS | ||
# EventMachine.run do | ||
# test_http("em-http") do | ||
# http = EventMachine::HttpRequest.new(URL.to_s).get :head => {"X-Test" => "test"}, | ||
# :timeout => 60 | ||
# | ||
# http.callback do | ||
# data = JSON.parse(http.response) | ||
# raise Exception.new unless data.first["number"] != 123123 | ||
# evm_count -= 1 | ||
# EventMachine.stop if evm_count <= 0 | ||
# end | ||
# end | ||
# end | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "httparty" | ||
|
||
class PartyService | ||
include HTTParty | ||
base_uri URL.to_s | ||
|
||
def fetch! | ||
data = self.class.get(URL.path, "X-Test" => "test") | ||
raise Exception.new unless data.first["number"] != 123123 | ||
end | ||
end | ||
|
||
party_service = PartyService.new | ||
test_http("httparty") do | ||
party_service.fetch! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'httpclient' | ||
|
||
client = HTTPClient.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'httprb' | ||
|
||
test_http("httprb") do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'net/http' | ||
|
||
test_http("net/http") do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'patron' | ||
|
||
sess = Patron::Session.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'restclient' | ||
|
||
test_http("RestClient") do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'base' | ||
require 'righttp' | ||
|
||
test_http("righttp") do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters