Modified:
branches/RB-0.2/lib/ewgi/test/src/mochiweb_hello.erl
branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_get.erl
branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_post.erl
branches/RB-0.2/lib/ewgi/test/src/yaws_hello.erl
Log:
Modified tests to fit newly revised spec
TODO: Actually run them ;)
Modified: branches/RB-0.2/lib/ewgi/test/src/mochiweb_hello.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/test/src/mochiweb_hello.erl (original)
+++ branches/RB-0.2/lib/ewgi/test/src/mochiweb_hello.erl Fri Oct 10
11:42:41 2008
@@ -1,5 +1,5 @@
-module(mochiweb_hello).
--export([start/0, loop/1, stop/0, handle_req/2]).
+-export([start/0, loop/1, stop/0, handle_req/1]).
-define(DEFAULTS, [{name, ?MODULE},
{port, 8084}]).
@@ -10,11 +10,11 @@
mochiweb_http:stop(?MODULE).
loop(Req) ->
- M = ewgi_mochiweb:new(fun ?MODULE:handle_req/2),
+ M = ewgi_mochiweb:new(fun ?MODULE:handle_req/1),
M:run(Req).
-handle_req(Env, StartResp) ->
- error_logger:info_report(Env),
+handle_req(Ctx) ->
+ error_logger:info_report(Ctx),
{ok, C} = sgte:compile("
<html>
<head><title>Hello world</title></head>
@@ -26,5 +26,5 @@
</form>
</body>
</html>"),
- sgte:render(C, []).
-
+ Body = sgte:render(C, []),
+ ewgi_api:set_response(#ewgi_response{status={200, "OK"},
message_body=Body, headers=[]}, Ctx).
Modified: branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_get.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_get.erl (original)
+++ branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_get.erl Fri Oct 10
11:42:41 2008
@@ -3,7 +3,7 @@
-include_lib("../include/ewgi_unit.hrl").
-include("../../include/ewgi.hrl").
--export([loop/1, handle_req/2]).
+-export([loop/1, handle_req/1]).
-define(PORT, 8000).
@@ -29,36 +29,36 @@
end.
loop(Req) ->
- M = ewgi_mochiweb:new(fun ?MODULE:handle_req/2),
+ M = ewgi_mochiweb:new(fun ?MODULE:handle_req/1),
M:run(Req).
-handle_req(Env, StartResp) ->
- ?eq(ewgi_api:server_sw(Env), "MochiWeb"),
- ?eq(ewgi_api:server_name(Env), "localhost"),
- ?eq(ewgi_api:gw_interface(Env),"EWGI/1.0"),
- ?eq(ewgi_api:server_protocol(Env), "HTTP/1.1"),
- ?eq(ewgi_api:server_port(Env), 8000),
- ?eq(ewgi_api:method(Env), 'GET'),
- ?eq(ewgi_api:path_info(Env), "/"),
- ?eq(ewgi_api:path_translated(Env), undefined),
- ?eq(ewgi_api:script_name(Env), ""),
+handle_req(Ctx) ->
+ ?eq(ewgi_api:server_software(Ctx), "MochiWeb"),
+ ?eq(ewgi_api:server_name(Ctx), "localhost"),
+ ?eq(ewgi_api:gateway_interface(Ctx),"EWGI/1.0"),
+ ?eq(ewgi_api:server_protocol(Ctx), "HTTP/1.1"),
+ ?eq(ewgi_api:server_port(Ctx), 8000),
+ ?eq(ewgi_api:request_method(Ctx), 'GET'),
+ ?eq(ewgi_api:path_info(Ctx), "/"),
+ ?eq(ewgi_api:path_translated(Ctx), undefined),
+ ?eq(ewgi_api:script_name(Ctx), ""),
% same hanlder for 2 GET requests.
% one has a query string and one hasn't
% check for both
- Qs = ewgi_api:qs(Env),
+ Qs = ewgi_api:query_string(Ctx),
?true((Qs=="") or (Qs==?DATA)),
- ?eq(ewgi_api:content_type(Env), undefined),
- ?eq(ewgi_api:content_length(Env), undefined),
+ ?eq(ewgi_api:content_type(Ctx), undefined),
+ ?eq(ewgi_api:content_length(Ctx), undefined),
Headers = [{"HTTP_CONNECTION", "keep-alive"},
{"HTTP_HOST", "localhost"}, {"HTTP_TE", []}],
- ?eq(ewgi_api:get_all_headers(Env), Headers),
- ?eq(ewgi_api:remote_host(Env), undefined),
- ?eq(ewgi_api:remote_addr(Env), "127.0.0.1"),
- ?eq(ewgi_api:auth_type(Env), undefined),
- ?eq(ewgi_api:remote_user(Env), undefined),
- ?eq(ewgi_api:remote_ident(Env),undefined),
- ?eq(ewgi_api:url_scheme(Env), "http"),
- ?eq(ewgi_api:version(Env), {1, 0}),
- ?eq(ewgi_api:get_all_data(Env), []),
+ ?eq(ewgi_api:get_all_headers(Ctx), Headers),
+ ?eq(ewgi_api:remote_host(Ctx), undefined),
+ ?eq(ewgi_api:remote_addr(Ctx), "127.0.0.1"),
+ ?eq(ewgi_api:auth_type(Ctx), undefined),
+ ?eq(ewgi_api:remote_user(Ctx), undefined),
+ ?eq(ewgi_api:remote_ident(Ctx),undefined),
+ ?eq(ewgi_api:url_scheme(Ctx), "http"),
+ ?eq(ewgi_api:version(Ctx), {1, 0}),
+ ?eq(ewgi_api:get_all_data(Ctx), []),
StartResp(?OK, []),
?RESPONSE.
Modified: branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_post.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_post.erl (original)
+++ branches/RB-0.2/lib/ewgi/test/src/mochiweb_simple_post.erl Fri Oct 10
11:42:41 2008
@@ -3,7 +3,7 @@
-include_lib("../include/ewgi_unit.hrl").
-include("../../include/ewgi.hrl").
--export([loop/1, handle_req/2]).
+-export([loop/1, handle_req/1]).
-define(PORT, 8000).
@@ -29,37 +29,37 @@
end.
loop(Req) ->
- M = ewgi_mochiweb:new(fun ?MODULE:handle_req/2),
+ M = ewgi_mochiweb:new(fun ?MODULE:handle_req/1),
M:run(Req).
-handle_req(Env, StartResp) ->
- ?eq(ewgi_api:server_sw(Env), "MochiWeb"),
- ?eq(ewgi_api:server_name(Env), "localhost"),
- ?eq(ewgi_api:gw_interface(Env),"EWGI/1.0"),
- ?eq(ewgi_api:server_protocol(Env), "HTTP/1.1"),
- ?eq(ewgi_api:server_port(Env), 8000),
- ?eq(ewgi_api:method(Env), 'POST'),
- ?eq(ewgi_api:path_info(Env), "/"),
- ?eq(ewgi_api:path_translated(Env), undefined),
- ?eq(ewgi_api:script_name(Env), ""),
+handle_req(Ctx) ->
+ ?eq(ewgi_api:server_sw(Ctx), "MochiWeb"),
+ ?eq(ewgi_api:server_name(Ctx), "localhost"),
+ ?eq(ewgi_api:gw_interface(Ctx),"EWGI/1.0"),
+ ?eq(ewgi_api:server_protocol(Ctx), "HTTP/1.1"),
+ ?eq(ewgi_api:server_port(Ctx), 8000),
+ ?eq(ewgi_api:method(Ctx), 'POST'),
+ ?eq(ewgi_api:path_info(Ctx), "/"),
+ ?eq(ewgi_api:path_translated(Ctx), undefined),
+ ?eq(ewgi_api:script_name(Ctx), ""),
% same hanlder for 2 GET requests.
% one has a query string and one hasn't
% check for both
- ?eq(ewgi_api:qs(Env),""),
- ?eq(ewgi_api:content_type(Env), ?CONTENT_TYPE),
- ?eq(ewgi_api:content_length(Env), length(?DATA)),
+ ?eq(ewgi_api:qs(Ctx),""),
+ ?eq(ewgi_api:content_type(Ctx), ?CONTENT_TYPE),
+ ?eq(ewgi_api:content_length(Ctx), length(?DATA)),
Headers = [{"HTTP_CONNECTION", "keep-alive"},
{"HTTP_HOST", "localhost"},
{"HTTP_TE", []}],
- ?eq(ewgi_api:get_all_headers(Env), Headers),
- ?eq(ewgi_api:remote_host(Env), undefined),
- ?eq(ewgi_api:remote_addr(Env), "127.0.0.1"),
- ?eq(ewgi_api:auth_type(Env), undefined),
- ?eq(ewgi_api:remote_user(Env), undefined),
- ?eq(ewgi_api:remote_ident(Env),undefined),
- ?eq(ewgi_api:url_scheme(Env), "http"),
- ?eq(ewgi_api:version(Env), {1, 0}),
- ?eq(ewgi_api:get_all_data(Env), []),
+ ?eq(ewgi_api:get_all_headers(Ctx), Headers),
+ ?eq(ewgi_api:remote_host(Ctx), undefined),
+ ?eq(ewgi_api:remote_addr(Ctx), "127.0.0.1"),
+ ?eq(ewgi_api:auth_type(Ctx), undefined),
+ ?eq(ewgi_api:remote_user(Ctx), undefined),
+ ?eq(ewgi_api:remote_ident(Ctx),undefined),
+ ?eq(ewgi_api:url_scheme(Ctx), "http"),
+ ?eq(ewgi_api:version(Ctx), {1, 0}),
+ ?eq(ewgi_api:get_all_data(Ctx), []),
StartResp(?OK, []),
?RESPONSE.
Modified: branches/RB-0.2/lib/ewgi/test/src/yaws_hello.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/test/src/yaws_hello.erl (original)
+++ branches/RB-0.2/lib/ewgi/test/src/yaws_hello.erl Fri Oct 10 11:42:41
2008
@@ -15,11 +15,11 @@
%% API
%%====================================================================
out(Arg) ->
- M = ewgi_yaws:new(fun ?MODULE:handle_req/2),
+ M = ewgi_yaws:new(fun ?MODULE:handle_req/1),
M:run(Arg).
-handle_req(Env, StartResp) ->
- error_logger:info_report(Env),
+handle_req(Ctx) ->
+ error_logger:info_report(Ctx),
{ok, C} = sgte:compile("
<html>
<head><title>Hello world</title></head>
@@ -31,7 +31,8 @@
</form>
</body>
</html>"),
- sgte:render(C, []).
+ Body = sgte:render(C, []),
+ ewgi_api:set_response(#ewgi_response{status={200, "OK"}, headers=[],
message_body=Body}, Ctx).
%%====================================================================
%% Internal functions