Permalink
Browse files

Formatting cleanup

  • Loading branch information...
1 parent 21ae9a6 commit 62423f1c9d00e75f8aeef0d7a7fa7c8bdd5c1efd Johannes Huning committed Feb 28, 2013
Showing with 46 additions and 45 deletions.
  1. +1 −2 LICENSE
  2. +29 −30 include/etest_http.hrl
  3. +14 −11 src/etest_http.erl
  4. +2 −2 src/etest_http_json.erl
View
@@ -1,5 +1,4 @@
-Copyright (c) 2012, Johannes Huning, Wooga GmbH
-All rights reserved.
+Copyright (c) 2012 Wooga GmbH - All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
View
@@ -1,4 +1,3 @@
-%% @author Johannes Huning <johannes.huning@wooga.com>
%% @doc ETest HTTP related assertions.
-ifndef(ETEST_HTTP_HRL).
-define(ETEST_HTTP_HRL, true).
@@ -33,12 +32,12 @@
-define (perform_put(Url, Headers, Body),
?perform_put(Url, Headers, Body, [])).
-define (perform_put(Url, Headers, Body, Queries),
- ?perform_request(put, Url, Headers, Queries, Body)).
+ ?perform_request(put, Url, Headers, Queries, Body)).
-define (perform_delete(Url), ?perform_delete(Url, [])).
-define (perform_delete(Url, Headers), ?perform_delete(Url, Headers, [])).
-define (perform_delete(Url, Headers, Queries),
- ?perform_request(delete, Url, Headers, Queries, <<>>)).
+ ?perform_request(delete, Url, Headers, Queries, <<>>)).
-define (perform_request(Method, Url, Headers, Queries, Body),
@@ -137,52 +136,52 @@ end)(Res))).
case etest_http_json:fetch(Key, __JsonStruct, '__undefined__') of
'__undefined__' ->
erlang:error({assert_json_key,
- [{module, ?MODULE},
- {line, ?LINE},
+ [{module, ?MODULE},
+ {line, ?LINE},
{expected_expression, (??Key)},
- {expected_value, Key},
- {got_value, undefined}] });
+ {expected_value, Key},
+ {got_value, undefined}] });
_ -> ok
end
end)(Res))).
-define(assert_json_values(__Queries, __Response),
- [?assert_json_value(__K, __V, __Response) || {__K, __V} <- __Queries]).
+ [?assert_json_value(__K, __V, __Response) || {__K, __V} <- __Queries]).
-define (assert_json_value(Key, Value0, Res),
((fun(Value, __Res) ->
__JsonStruct = etest_http_json:decode(__Res#etest_http_res.body),
case etest_http_json:fetch(Key, __JsonStruct, '__undefined__') of
Value -> ok;
__V -> erlang:error({assert_json_val,
- [{module, ?MODULE},
- {line, ?LINE},
+ [{module, ?MODULE},
+ {line, ?LINE},
{expected_expression, (??Value0)},
- {expected_value, Value0},
- {got_value, __V}] })
+ {expected_value, Value0},
+ {got_value, __V}] })
end
end)(Value0, Res))).
-define(get_json_value(__Key, __Response),
((fun
- (__Key, __JsonStructBin) when is_binary(__JsonStructBin) ->
- __JsonStruct = etest_http_json:decode(__JsonStructBin),
- case etest_http_json:fetch(__Key, __JsonStruct, undefined) of
- undefined -> .erlang:error({json_val_undefined,
- [{json_struct, __JsonStruct},
- {module, ?MODULE},
- {line, ?LINE}] });
- Value -> Value
- end;
-
- (__Key, __Res) ->
- __JsonStruct = etest_http_json:decode(__Res#etest_http_res.body),
- case etest_http_json:fetch(__Key, __JsonStruct, undefined) of
- undefined -> .erlang:error({json_val_undefined,
- [{module, ?MODULE},
- {line, ?LINE}] });
- Value -> Value
- end
+ (__Key, __JsonStructBin) when is_binary(__JsonStructBin) ->
+ __JsonStruct = etest_http_json:decode(__JsonStructBin),
+ case etest_http_json:fetch(__Key, __JsonStruct, undefined) of
+ undefined -> erlang:error({json_val_undefined,
+ [{json_struct, __JsonStruct},
+ {module, ?MODULE},
+ {line, ?LINE}] });
+ Value -> Value
+ end;
+
+ (__Key, __Res) ->
+ __JsonStruct = etest_http_json:decode(__Res#etest_http_res.body),
+ case etest_http_json:fetch(__Key, __JsonStruct, undefined) of
+ undefined -> erlang:error({json_val_undefined,
+ [{module, ?MODULE},
+ {line, ?LINE}] });
+ Value -> Value
+ end
end)(__Key, __Response))).
-endif. % ETEST_HTTP_HRL.
View
@@ -1,4 +1,3 @@
-%% @author Johannes Huning <johannes.huning@wooga.com>
-module (etest_http).
-export ([perform_request/5]).
@@ -16,7 +15,7 @@ perform_request(Method, Url, Headers, Queries, Body) ->
FullUrl = Url ++ query_string(Queries),
Request = case Method of
get -> {FullUrl, Headers};
- delete -> {FullUrl, Headers};
+ delete -> {FullUrl, Headers};
_ -> {FullUrl, Headers, "", Body}
end,
@@ -38,19 +37,23 @@ query_string([Head|Tail]) ->
query_string([]) -> [].
- %% Value to list
+% Value to list
make_query({Key, Value}) when
- Value =:= true orelse
- Value =:= false ->
- make_query({Key, atom_to_list(Value)});
+ Value =:= true orelse
+ Value =:= false ->
+ make_query({Key, atom_to_list(Value)});
+
make_query({Key, Value}) when is_binary(Value) ->
- make_query({Key, binary_to_list(Value)});
+ make_query({Key, binary_to_list(Value)});
+
make_query({Key, Value}) when is_integer(Value) ->
- make_query({Key, integer_to_list(Value)});
- %% Key to list
+ make_query({Key, integer_to_list(Value)});
+
+% Key to list
make_query({Key, Value}) when is_atom(Key) ->
- make_query({atom_to_list(Key), Value});
- %% key & value lists
+ make_query({atom_to_list(Key), Value});
+
+% Key & value lists
make_query({Key, Value}) when is_list(Key) andalso is_list(Value) ->
[url_encode(Key), "=", url_encode(Value)].
View
@@ -1,4 +1,3 @@
-%% @author Johannes Huning <johannes.huning@wooga.com>
%% @doc JSON specific helper functions.
-module (etest_http_json).
@@ -38,7 +37,8 @@ fetch([Parent|Rest], Orddict) ->
fetch(Rest, fetch(Parent, Orddict));
fetch(Key, Orddict) when is_atom(Key) ->
- fetch(atom_to_binary(Key, latin1), Orddict);
+ fetch(atom_to_binary(Key, latin1), Orddict);
+
fetch(Key, Orddict) ->
orddict:fetch(Key, Orddict).

0 comments on commit 62423f1

Please sign in to comment.