-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathrunner_test.exs
More file actions
130 lines (105 loc) · 3.03 KB
/
runner_test.exs
File metadata and controls
130 lines (105 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
defmodule ReverseProxy.RunnerTest do
use ExUnit.Case
use Plug.Test
test "retreive/2 - plug - success" do
conn = conn(:get, "/")
conn = ReverseProxy.Runner.retreive(
conn,
{ReverseProxyTest.SuccessPlug, []}
)
assert conn.status == 200
assert conn.resp_body == "success"
end
test "retreive/2 - plug - success with response headers" do
conn = conn(:get, "/")
headers = [
{"cache-control", "max-age=0, private, must-revalidate"},
{"x-header-1", "yes"},
{"x-header-2", "yes"}
]
conn = ReverseProxy.Runner.retreive(
conn,
{ReverseProxyTest.SuccessPlug, headers: headers}
)
assert conn.status == 200
assert conn.resp_body == "success"
assert conn.resp_headers == headers
end
test "retreive/2 - plug - failure" do
conn = conn(:get, "/")
conn = ReverseProxy.Runner.retreive(
conn,
{ReverseProxyTest.FailurePlug, []}
)
assert conn.status == 500
assert conn.resp_body == "failure"
end
test "retreive/3 - http - success" do
conn = conn(:get, "/")
conn = ReverseProxy.Runner.retreive(
conn,
["localhost"],
ReverseProxyTest.SuccessHTTP
)
assert conn.status == 200
assert conn.resp_body == "success"
end
test "retrieve/3 - partial body" do
conn =
conn(:post, "/", String.duplicate("_", 8_000_000 + 1))
|> put_req_header("content-type", "application/json")
|> ReverseProxy.Runner.retreive(
["localhost"],
ReverseProxyTest.BodyLength
)
assert conn.resp_body == "8000001"
end
test "retrieve/3 - chunked response" do
conn =
conn(:get, "/")
|> ReverseProxy.Runner.retreive(
["localhost"],
ReverseProxyTest.ChunkedResponse
)
assert get_resp_header(conn, "transfer-encoding") == []
end
test "retreive/3 - http - success with response headers" do
conn = conn(:get, "/")
headers = ReverseProxyTest.SuccessHTTP.headers
conn = ReverseProxy.Runner.retreive(
conn,
["localhost"],
ReverseProxyTest.SuccessHTTP
)
assert conn.status == 200
assert conn.resp_body == "success"
assert conn.resp_headers == headers
end
test "retreive/3 - http - location header rewrite" do
conn = conn(:get, "/")
|> put_req_header("host", "localhost:4000")
conn = ReverseProxy.Runner.retreive(
conn,
["localhost:5001"],
ReverseProxyTest.RedirectHTTP
)
assert conn.status == 301
assert conn.resp_body == """
<html><body>You are being <a href="http://localhost:4000/foo">redirected</a>.</body></html>
"""
assert conn.resp_headers == [
{"cache-control", "max-age=0, private, must-revalidate"},
{"location", "http://localhost:4000/foo"},
]
end
test "retreive/3 - http - failure" do
conn = conn(:get, "/")
conn = ReverseProxy.Runner.retreive(
conn,
["localhost"],
ReverseProxyTest.FailureHTTP
)
assert conn.status == 502
assert conn.resp_body == "Bad Gateway"
end
end