nginx_test_helper 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/nginx_test_helper.rb +10 -7
- data/lib/nginx_test_helper/version.rb +1 -1
- data/spec/nginx_test_helper_spec.rb +38 -6
- metadata +3 -3
data/lib/nginx_test_helper.rb
CHANGED
@@ -4,7 +4,8 @@ require "nginx_test_helper/config"
|
|
4
4
|
require "nginx_test_helper/rspec_utils"
|
5
5
|
require "nginx_test_helper/command_line_tool"
|
6
6
|
require "popen4"
|
7
|
-
require
|
7
|
+
require "timeout"
|
8
|
+
require "socket"
|
8
9
|
|
9
10
|
module NginxTestHelper
|
10
11
|
include NginxTestHelper::EnvMethods
|
@@ -30,14 +31,16 @@ module NginxTestHelper
|
|
30
31
|
TCPSocket.open(host, port)
|
31
32
|
end
|
32
33
|
|
33
|
-
def get_in_socket(url, socket,
|
34
|
-
|
35
|
-
|
34
|
+
def get_in_socket(url, socket, options={})
|
35
|
+
options = {:use_http_1_0 => false, :host_header => "localhost"}.merge(options)
|
36
|
+
socket.print("GET #{url} HTTP/1.#{options[:use_http_1_0] ? "0" : "1\r\nHost: #{options[:host_header]}"}\r\n\r\n")
|
37
|
+
read_response_on_socket(socket, options[:wait_for])
|
36
38
|
end
|
37
39
|
|
38
|
-
def post_in_socket(url, body, socket,
|
39
|
-
|
40
|
-
|
40
|
+
def post_in_socket(url, body, socket, options={})
|
41
|
+
options = {:use_http_1_0 => false, :host_header => "localhost"}.merge(options)
|
42
|
+
socket.print("POST #{url} HTTP/1.#{options[:use_http_1_0] ? "0" : "1\r\nHost: #{options[:host_header]}"}\r\nContent-Length: #{body.size}\r\n\r\n#{body}")
|
43
|
+
read_response_on_socket(socket, options[:wait_for])
|
41
44
|
end
|
42
45
|
|
43
46
|
def read_response_on_socket(socket, wait_for=nil)
|
@@ -25,33 +25,65 @@ describe NginxTestHelper do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should be possible to do a GET in an url using the opened socket, and receive header and body response" do
|
28
|
-
socket.should_receive(:print).with("GET /index.html HTTP/1.
|
28
|
+
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n")
|
29
29
|
|
30
30
|
headers, body = get_in_socket("/index.html", socket)
|
31
31
|
headers.should eql("HTTP 200 OK")
|
32
32
|
body.should eql("BODY")
|
33
33
|
end
|
34
34
|
|
35
|
-
it "should
|
35
|
+
it "should be possible specify the host header value to do a GET" do
|
36
|
+
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: some_host_value\r\n\r\n")
|
37
|
+
|
38
|
+
headers, body = get_in_socket("/index.html", socket, {:host_header => "some_host_value"})
|
39
|
+
headers.should eql("HTTP 200 OK")
|
40
|
+
body.should eql("BODY")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be possible use http 1.0 to do a GET" do
|
36
44
|
socket.should_receive(:print).with("GET /index.html HTTP/1.0\r\n\r\n")
|
45
|
+
|
46
|
+
headers, body = get_in_socket("/index.html", socket, {:use_http_1_0 => true})
|
47
|
+
headers.should eql("HTTP 200 OK")
|
48
|
+
body.should eql("BODY")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should pass 'wait_for' attribute to 'read_response_on_socket' method when doing a GET in a url" do
|
52
|
+
socket.should_receive(:print).with("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n")
|
37
53
|
self.should_receive(:read_response_on_socket).with(socket, "wait for")
|
38
54
|
|
39
|
-
get_in_socket("/index.html", socket, "wait for")
|
55
|
+
get_in_socket("/index.html", socket, {:wait_for => "wait for"})
|
40
56
|
end
|
41
57
|
|
42
58
|
it "should be possible to do a POST in an url using the opened socket, and receive header and body response" do
|
43
|
-
socket.should_receive(:print).with("POST /service HTTP/1.
|
59
|
+
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\n\r\nBODY")
|
44
60
|
|
45
61
|
headers, body = post_in_socket("/service", "BODY", socket)
|
46
62
|
headers.should eql("HTTP 200 OK")
|
47
63
|
body.should eql("BODY")
|
48
64
|
end
|
49
65
|
|
50
|
-
it "should
|
66
|
+
it "should be possible specify the host header value to do a POST" do
|
67
|
+
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: some_host_value\r\nContent-Length: 4\r\n\r\nBODY")
|
68
|
+
|
69
|
+
headers, body = post_in_socket("/service", "BODY", socket, {:host_header => "some_host_value"})
|
70
|
+
headers.should eql("HTTP 200 OK")
|
71
|
+
body.should eql("BODY")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be possible use http 1.0 to do a POST" do
|
51
75
|
socket.should_receive(:print).with("POST /service HTTP/1.0\r\nContent-Length: 4\r\n\r\nBODY")
|
76
|
+
|
77
|
+
headers, body = post_in_socket("/service", "BODY", socket, {:use_http_1_0 => true})
|
78
|
+
headers.should eql("HTTP 200 OK")
|
79
|
+
body.should eql("BODY")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should pass 'wait_for' attribute to 'read_response_on_socket' method when doing a POST in a url" do
|
83
|
+
socket.should_receive(:print).with("POST /service HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\n\r\nBODY")
|
52
84
|
self.should_receive(:read_response_on_socket).with(socket, "wait for")
|
53
85
|
|
54
|
-
headers, body = post_in_socket("/service", "BODY", socket, "wait for")
|
86
|
+
headers, body = post_in_socket("/service", "BODY", socket, {:wait_for => "wait for"})
|
55
87
|
end
|
56
88
|
|
57
89
|
it "should be possible read a response in a opened socket" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginx_test_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: popen4
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.25
|
131
131
|
signing_key:
|
132
132
|
specification_version: 3
|
133
133
|
summary: A collection of helper methods to test your nginx module.
|