Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #211] Add meta testing and Fix dialyzer warnings #230

Merged
merged 1 commit into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ dep_riakc = git https://github.com/inaka/riak-erlang-client.git 2.1.1-R18
dep_uuid = git https://github.com/okeuday/uuid.git 31f408f4ef
dep_iso8601 = git https://github.com/zerotao/erlang_iso8601.git 0d14540

TEST_DEPS = mixer
dep_mixer = git git://github.com/inaka/mixer.git 0.1.5
TEST_DEPS = katana mixer
dep_katana = git https://github.com/inaka/erlang-katana.git 0.2.22
dep_mixer = git https://github.com/inaka/mixer.git 0.1.5

CT_SUITES ?= conditional_logic sumo_basic sumo_config sumo_find sumo_events
CT_SUITES ?= conditional_logic sumo_basic sumo_config sumo_find sumo_events sumo_meta

include erlang.mk

Expand Down
4 changes: 3 additions & 1 deletion src/sumo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
| {field_name(), operator(), field_value()}
| {field_name(), operator(), field_name()}.
-type sort_order() :: asc | desc.
-type sort() :: field_name() | [{field_name(), sort_order()}].
-type sort() :: field_name()
| {field_name(), sort_order()}
| [{field_name(), sort_order()}].

-export_type([schema_name/0, field_attr/0, field_attrs/0, field_type/0,
field_name/0, field_value/0, doc/0, conditions/0,
Expand Down
2 changes: 1 addition & 1 deletion test/riak/nested_docs_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all() ->

-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
application:ensure_all_started(sumo_db),
{ok, _} = application:ensure_all_started(sumo_db),
Config.

init_per_testcase(_, Config) ->
Expand Down
25 changes: 19 additions & 6 deletions test/riak/sumo_test_purchase_order.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
id => binary(),
created_at => binary(),
order_num => binary(),
po_date => binary(),
po_date => calendar:datetime(),
ship_to => address(),
bill_to => address(),
items => items(),
Expand All @@ -52,9 +52,9 @@ sumo_schema() ->
, sumo:new_field(created_at, datetime, [not_null])
, sumo:new_field(order_num, binary, [not_null])
, sumo:new_field(po_date, datetime, [not_null])
, sumo:new_field(ship_to, address, [not_null])
, sumo:new_field(bill_to, address, [not_null])
, sumo:new_field(items, items, [not_null])
, sumo:new_field(ship_to, binary, [not_null])
, sumo:new_field(bill_to, binary, [not_null])
, sumo:new_field(items, binary, [not_null])
, sumo:new_field(currency, binary, [not_null])
, sumo:new_field(total, integer, [not_null])
]).
Expand Down Expand Up @@ -88,7 +88,7 @@ sumo_wakeup(Doc) ->
-spec new(
binary(),
binary(),
binary(),
calendar:datetime(),
address(),
address(),
items(),
Expand Down Expand Up @@ -124,7 +124,7 @@ order_num(#{order_num := Val}) ->
order_num(PO, Val) ->
maps:put(order_num, Val, PO).

-spec items(purchase_order()) -> item().
-spec items(purchase_order()) -> items().
items(#{items := Val}) ->
Val.

Expand All @@ -140,6 +140,13 @@ currency(#{currency := Val}) ->
currency(PO, Val) ->
maps:put(currency, Val, PO).

-spec new_address(Line1::binary(),
Line2::binary(),
City::binary(),
State::binary(),
ZipCode::binary(),
Country::binary()) ->
address().
new_address(Line1, Line2, City, State, ZipCode, Country) ->
#{
line1 => Line1,
Expand All @@ -150,6 +157,12 @@ new_address(Line1, Line2, City, State, ZipCode, Country) ->
country => Country
}.

-spec new_item(PartNum::binary(),
Name::binary(),
Quantity::pos_integer(),
UnitPrice::pos_integer(),
Price::pos_integer()) ->
item().
new_item(PartNum, Name, Quantity, UnitPrice, Price) ->
#{
part_num => PartNum,
Expand Down
17 changes: 17 additions & 0 deletions test/sumo_meta_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-module(sumo_meta_SUITE).

-include_lib("mixer/include/mixer.hrl").
-mixin([{ktn_meta_SUITE
, [ all/0
, xref/1
, dialyzer/1
, elvis/1
]
}]).

-export([init_per_suite/1]).

-type config() :: [{atom(), term()}].

-spec init_per_suite(config()) -> config().
init_per_suite(Config) -> [{application, sumo_db} | Config].
102 changes: 86 additions & 16 deletions test/sumo_test_people.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

%%% sumo_db callbacks
-export([
sumo_schema/0,
sumo_wakeup/1,
sumo_sleep/1
]).
Expand All @@ -26,24 +27,38 @@
description/1,
profile_image/1]).

-record(person, {id :: integer() | binary(),
name :: binary(),
last_name :: binary(),
age :: integer(),
address :: binary(),
birthdate :: calendar:date(),
created_at :: calendar:datetime(),
height :: float(),
description :: binary(),
profile_image :: binary()}).
-type id() :: integer() | binary().
-type name() :: binary().
-type last_name() :: binary().
-type age() :: integer() | undefined.
-type address() :: binary() | undefined.
-type birthdate() :: calendar:date() | undefined.
-type created_at() :: calendar:datetime().
-type height() :: float() | undefined.
-type description() :: binary() | undefined.
-type profile_image() :: binary() | undefined.

-record(person, {id :: id(),
name :: name(),
last_name :: last_name(),
age :: age(),
address :: address(),
birthdate :: birthdate(),
created_at :: created_at(),
height :: height(),
description :: description(),
profile_image :: profile_image()}).

-type person() :: #person{}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% sumo_doc callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec sumo_sleep(person()) -> sumo:doc().
-spec sumo_schema() -> no_return().
sumo_schema() -> throw(should_be_implemented_by_children).

-spec sumo_sleep(Person::person()) -> sumo:doc().
sumo_sleep(Person) ->
#{id => Person#person.id,
name => Person#person.name,
Expand All @@ -56,7 +71,7 @@ sumo_sleep(Person) ->
description => Person#person.description,
profile_image => Person#person.profile_image}.

-spec sumo_wakeup(sumo:doc()) -> person().
-spec sumo_wakeup(Person::sumo:doc()) -> person().
sumo_wakeup(Person) ->
#person{
id = maps:get(id, Person),
Expand All @@ -75,22 +90,67 @@ sumo_wakeup(Person) ->
%%% Exported
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

new(Name, LastName) -> new(Name, LastName, undefined).

new(Name, LastName, Age) -> new(Name, LastName, Age, undefined).

-spec new(Name::name(),
LastName::last_name()) ->
person().
new(Name, LastName) ->
new(Name, LastName, undefined).

-spec new(Name::name(),
LastName::last_name(),
Age::age()) ->
person().
new(Name, LastName, Age) ->
new(Name, LastName, Age, undefined).

-spec new(Name::name(),
LastName::last_name(),
Age::age(),
Address::address()) ->
person().
new(Name, LastName, Age, Address) ->
{BirthDate, _} = calendar:universal_time(),
new(Name, LastName, Age, Address, BirthDate).

-spec new(Name::name(),
LastName::last_name(),
Age::age(),
Address::address(),
BirthDate::birthdate()) ->
person().
new(Name, LastName, Age, Address, BirthDate) ->
new(Name, LastName, Age, Address, BirthDate, undefined).

-spec new(Name::name(),
LastName::last_name(),
Age::age(),
Address::address(),
BirthDate::birthdate(),
Height::height()) ->
person().
new(Name, LastName, Age, Address, BirthDate, Height) ->
new(Name, LastName, Age, Address, BirthDate, Height, undefined).

-spec new(Name::name(),
LastName::last_name(),
Age::age(),
Address::address(),
BirthDate::birthdate(),
Height::height(),
Description::description()) ->
person().
new(Name, LastName, Age, Address, BirthDate, Height, Description) ->
new(Name, LastName, Age, Address, BirthDate, Height, Description, undefined).

-spec new(Name::name(),
LastName::last_name(),
Age::age(),
Address::address(),
BirthDate::birthdate(),
Height::height(),
Description::description(),
ProfileImage::profile_image()) ->
person().
new(Name,
LastName,
Age,
Expand All @@ -110,32 +170,42 @@ new(Name,
description = Description,
profile_image = ProfileImage}.

-spec name(Person::person()) -> name().
name(Person) ->
Person#person.name.

-spec last_name(Person::person()) -> last_name().
last_name(Person) ->
Person#person.last_name.

-spec id(Person::person()) -> id().
id(Person) ->
Person#person.id.

-spec age(Person::person()) -> age().
age(Person) ->
Person#person.age.

-spec address(Person::person()) -> address().
address(Person) ->
Person#person.address.

-spec birthdate(Person::person()) -> birthdate().
birthdate(Person) ->
Person#person.birthdate.

-spec created_at(Person::person()) -> created_at().
created_at(Person) ->
Person#person.created_at.

-spec height(Person::person()) -> height().
height(Person) ->
Person#person.height.

-spec description(Person::person()) -> description().
description(Person) ->
Person#person.description.

-spec profile_image(Person::person()) -> profile_image().
profile_image(Person) ->
Person#person.profile_image.
3 changes: 3 additions & 0 deletions test/sumo_test_people_elasticsearch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
3 changes: 3 additions & 0 deletions test/sumo_test_people_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
3 changes: 3 additions & 0 deletions test/sumo_test_people_mongo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
3 changes: 3 additions & 0 deletions test/sumo_test_people_mysql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
3 changes: 3 additions & 0 deletions test/sumo_test_people_pgsql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
3 changes: 3 additions & 0 deletions test/sumo_test_people_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

-behavior(sumo_doc).

%% @todo remove this once mixer migrates specs better
-dialyzer([no_behaviours]).

-include_lib("mixer/include/mixer.hrl").
-mixin([{sumo_test_people,
[sumo_wakeup/1,
Expand Down
4 changes: 2 additions & 2 deletions test/sumo_test_store.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ persist(Doc, State) ->
%% sumo_store custom functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec takes_too_long(atom(), term()) ->
[thoughtz_thoughtz:thought()].
-spec takes_too_long(DocName::atom(), State::term()) ->
{ok, {docs, []}, term()}.
takes_too_long(_DocName, State) ->
timer:sleep(1000),
{ok, {docs, []}, State}.
8 changes: 6 additions & 2 deletions test/sumo_test_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ start_apps() ->
{ok, _} = application:ensure_all_started(epgsql),
{ok, _} = application:ensure_all_started(emongo),
{ok, _} = application:ensure_all_started(tirerl),
mnesia:create_schema([node()]),
ok = case mnesia:create_schema([node()]) of
ok -> ok;
{error, {_Host, {already_exists, _Host}}} -> ok
end,
{ok, _} = application:ensure_all_started(mnesia),
{ok, _} = application:ensure_all_started(sumo_db).
{ok, _} = application:ensure_all_started(sumo_db),
ok.

-spec all_people() -> [atom()].
all_people() ->
Expand Down