Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convert existing test functions to eunit

  • Loading branch information...
commit 6b2591391def045c606bd60da2a615a463423782 1 parent 93d4762
@beerriot beerriot authored
Showing with 35 additions and 25 deletions.
  1. +25 −17 src/webmachine_multipart.erl
  2. +10 −8 src/webmachine_util.erl
View
42 src/webmachine_multipart.erl
@@ -20,7 +20,8 @@
-author('Justin Sheehy <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
-export([get_all_parts/2,stream_parts/2, find_boundary/1]).
--export([test_body/0,test_body2/0]).
+
+-include_lib("eunit/include/eunit.hrl").
% @type incoming_req_body() = binary().
% The request body, in "multipart/form-data" (rfc2388) form,
@@ -142,24 +143,31 @@ send_streamed_body(Body, Max) ->
{Body, done}
end.
-test_body() ->
+body_test() ->
Body = <<"------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Filename\"\r\n\r\ntestfile.txt\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"testfile.txt\"\r\nContent-Type: application/octet-stream\r\n\r\n%%% The contents of this file are a test,\n%%% do not be alarmed.\n\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2--">>,
Boundary = "----------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2",
- [{"Filename",
- {[{<<"name">>,<<"Filename">>}],[]},
- <<"testfile.txt\r\n">>},
- {"Filedata",
- {[{<<"name">>,<<"Filedata">>},
- {<<"filename">>,<<"testfile.txt">>}],
- [{<<"Content-Type">>,<<"application/octet-stream">>}]},
- <<"%%% The contents of this file are a test,\n%%% do not be alarmed.\n\r\n">>},
- {"Upload",
- {[{<<"name">>,<<"Upload">>}],[]},
- <<"Submit Query\r\n">>}]
- = get_all_parts(Body, Boundary),
- ok.
+ ?assertEqual(
+ [{"Filename",
+ {[{<<"name">>,<<"Filename">>}],[]},
+ <<"testfile.txt\r\n">>},
+ {"Filedata",
+ {[{<<"name">>,<<"Filedata">>},
+ {<<"filename">>,<<"testfile.txt">>}],
+ [{<<"Content-Type">>,<<"application/octet-stream">>}]},
+ <<"%%% The contents of this file are a test,\n%%% do not be alarmed.\n\r\n">>},
+ {"Upload",
+ {[{<<"name">>,<<"Upload">>}],[]},
+ <<"Submit Query\r\n">>}],
+ get_all_parts(Body, Boundary)).
-test_body2() ->
+body2_test() ->
Body = <<"-----------------------------89205314411538515011004844897\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"akamai.txt\"\r\nContent-Type: text/plain\r\n\r\nCAMBRIDGE, MA - February 18, 2009 - Akamai Technologies, Inc. (NASDAQ: AKAM), the leader in powering rich media, dynamic transactions and enterprise applications online, today announced that its Service & Support organization was awarded top honors for Innovation in Customer Service at the 3rd Annual Stevie Awards for Sales & Customer Service, an international competition recognizing excellence in disciplines that are crucial to business success.\n\n\"We have always set incredibly high standards with respect to the service and support we provide our customers,\" said Sanjay Singh, vice president of Global Service & Support at Akamai. \"Our support team provides highly responsive service around the clock to our global customer base and, as a result, has become an extension of our customers' online businesses. This prestigious award is validation of Akamai's commitment to customer service and technical support.\"\n\nAkamai Service & Support professionals are dedicated to working with customers on a daily basis to fine tune, optimize, and support their Internet initiatives. Akamai's winning submission highlighted the key pillars of its service and support offering, as well as the initiatives established to meet customer requirements for proactive communication, simplification, and faster response times.\n\n\"This year's honorees demonstrate that even in challenging economic times, it's possible for organizations to continue to shine in sales and customer service, the two most important functions in business: acquiring and keeping customers,\" said Michael Gallagher, president of the Stevie Awards.\n\nThe awards are presented by the Stevie Awards, which organizes several of the world's leading business awards shows, including the prestigious American Business Awards. Nicknamed the Stevies for the Greek word \"crowned,\" winners were announced during a gala banquet on Monday, February 9 at Caesars Palace in Las Vegas. Nominated customer service and sales executives from the U.S.A. and several other countries attended. More than 500 entries from companies of all sizes and in virtually every industry were submitted to this year's competition. There are 27 categories for customer service professionals, as well as 41 categories for sales professionals.\n\nDetails about the Stevie Awards for Sales & Customer Service and the list of honorees in all categories are available at www.stevieawards.com/sales. \n\r\n-----------------------------89205314411538515011004844897--\r\n">>,
Boundary = "---------------------------89205314411538515011004844897",
- get_all_parts(Body,Boundary).
+ ?assertEqual(
+ [{"Filedata",
+ {[{<<"name">>,<<"Filedata">>},
+ {<<"filename">>,<<"akamai.txt">>}],
+ [{<<"Content-Type">>,<<"text/plain">>}]},
+ <<"CAMBRIDGE, MA - February 18, 2009 - Akamai Technologies, Inc. (NASDAQ: AKAM), the leader in powering rich media, dynamic transactions and enterprise applications online, today announced that its Service & Support organization was awarded top honors for Innovation in Customer Service at the 3rd Annual Stevie Awards for Sales & Customer Service, an international competition recognizing excellence in disciplines that are crucial to business success.\n\n\"We have always set incredibly high standards with respect to the service and support we provide our customers,\" said Sanjay Singh, vice president of Global Service & Support at Akamai. \"Our support team provides highly responsive service around the clock to our global customer base and, as a result, has become an extension of our customers' online businesses. This prestigious award is validation of Akamai's commitment to customer service and technical support.\"\n\nAkamai Service & Support professionals are dedicated to working with customers on a daily basis to fine tune, optimize, and support their Internet initiatives. Akamai's winning submission highlighted the key pillars of its service and support offering, as well as the initiatives established to meet customer requirements for proactive communication, simplification, and faster response times.\n\n\"This year's honorees demonstrate that even in challenging economic times, it's possible for organizations to continue to shine in sales and customer service, the two most important functions in business: acquiring and keeping customers,\" said Michael Gallagher, president of the Stevie Awards.\n\nThe awards are presented by the Stevie Awards, which organizes several of the world's leading business awards shows, including the prestigious American Business Awards. Nicknamed the Stevies for the Greek word \"crowned,\" winners were announced during a gala banquet on Monday, February 9 at Caesars Palace in Las Vegas. Nominated customer service and sales executives from the U.S.A. and several other countries attended. More than 500 entries from companies of all sizes and in virtually every industry were submitted to this year's competition. There are 27 categories for customer service professionals, as well as 41 categories for sales professionals.\n\nDetails about the Stevie Awards for Sales & Customer Service and the list of honorees in all categories are available at www.stevieawards.com/sales. \n\r\n">>
+ }],
+ get_all_parts(Body,Boundary)).
View
18 src/webmachine_util.erl
@@ -26,7 +26,8 @@
-export([unquote_header/1]).
-export([now_diff_milliseconds/2]).
-export([media_type_to_detail/1]).
--export([test/0]).
+
+-include_lib("eunit/include/eunit.hrl").
convert_request_date(Date) ->
try
@@ -288,14 +289,15 @@ now_diff_milliseconds({M,S,U}, {M,S1,U1}) ->
now_diff_milliseconds({M,S,U}, {M1,S1,U1}) ->
((M-M1)*1000000+(S-S1))*1000 + ((U-U1) div 1000).
-test() ->
- test_choose_media_type(),
- ok.
+%%
+%% TEST
+%%
-test_choose_media_type() ->
+choose_media_type_test() ->
Provided = "text/html",
ShouldMatch = ["*", "*/*", "text/*", "text/html"],
WantNone = ["foo", "text/xml", "application/*", "foo/bar/baz"],
- [ Provided = choose_media_type([Provided], I) || I <- ShouldMatch ],
- [ none = choose_media_type([Provided], I) || I <- WantNone ],
- ok.
+ [ ?assertEqual(Provided, choose_media_type([Provided], I))
+ || I <- ShouldMatch ],
+ [ ?assertEqual(none, choose_media_type([Provided], I))
+ || I <- WantNone ].
Please sign in to comment.
Something went wrong with that request. Please try again.