diff --git a/Makefile b/Makefile index 27b145d..63cde4b 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,22 @@ REBAR = $(shell which rebar3 || echo ./rebar3) ENABLE_STATIC = no all: ENABLE_STATIC=$(ENABLE_STATIC) $(REBAR) compile clean: $(REBAR) clean run: $(REBAR) shell --config app.config release: $(REBAR) release test.spec: test.spec.in cover.spec.in cat test.spec.in | sed -e "s,@PATH@,$(PWD)," > $(PWD)/test.spec cat cover.spec.in | sed -e "s,@PATH@,$(PWD)," > $(PWD)/cover.spec test: test.spec all - mkdir -p test_logs - ct_run -pa $(PWD)/apps/*/ebin -pa $(PWD)/deps/*/ebin -spec test.spec -erl_args -config $(PWD)/apps/kolab_guam/test/test.config -s kolab_guam + $(REBAR) ct --cover --readable --allow_user_terms diff --git a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl index 35d8696..ae13e0f 100644 --- a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl +++ b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl @@ -1,140 +1,139 @@ %% Copyright 2015 Kolab Systems AG (http://www.kolabsys.com) %% %% Aaron Seigo (Kolab Systems) %% %% This program is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% (at your option) any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program. If not, see . -module(kolab_guam_rules_SUITE). % easier than exporting by name -compile(export_all). % required for common_test to work --include("ct.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("../src/rules/kolab_guam_rule_filter_groupware.hrl"). %%%%%%%%%%%%%%%%%%%%%%%%%%% %% common test callbacks %% %%%%%%%%%%%%%%%%%%%%%%%%%%% % Specify a list of all unit test functions all() -> [ kolab_guam_rule_filter_groupware_responsefiltering_test, kolab_guam_rule_filter_groupware_responsefiltering_multipacket_test ]. % required, but can just return Config. this is a suite level setup function. init_per_suite(Config) -> - application:load(kolab_guam), Config. % required, but can just return Config. this is a suite level tear down function. end_per_suite(Config) -> Config. % optional, can do function level setup for all functions, % or for individual functions by matching on TestCase. init_per_testcase(_TestCase, Config) -> Config. % optional, can do function level tear down for all functions, % or for individual functions by matching on TestCase. end_per_testcase(_TestCase, Config) -> Config. % c("apps/kolab_guam/test/kolab_guam_sup_tests.erl"). eunit:test(kolab_guam_sup_tests). kolab_guam_rule_filter_groupware_responsefiltering_test(_TestConfig) -> %% Data to be fed into the test, one tuple per iteration %% Tuple format: { [] = folder_blacklist, input_data, correct_output } Data = [ { [ {<<"Calendar">>, <<"Calendar/">>}, {<<"Calendar/Personal Calendar">>, <<"Calendar/Personal Calendar/">>}, {<<"Configuration">>, <<"Configuration/">>}, {<<"Contacts">>, <<"Contacts/">>}, {<<"Contacts/Personal Contacts">>, <<"Contacts/Personal Contacts/">>}, {<<"Files">>, <<"Files/">>}, {<<"Journal">>, <<"Journal/">>}, {<<"Notes">>, <<"Notes/">>}, {<<"Tasks">>, <<"Tasks/">>} ], <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Calendar\r\n* LIST (\\Subscribed) \"/\" \"Calendar/Personal Calendar\"\r\n* LIST (\\Subscribed) \"/\" Configuration\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Contacts\r\n* LIST (\\Subscribed) \"/\" \"Contacts/Personal Contacts\"\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Files\r\n* LIST (\\Subscribed) \"/\" Journal\r\n* LIST (\\Subscribed) \"/\" Notes\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Tasks\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">>, <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> } ], %% setup boilerplate Config = {}, %%TODO? State = kolab_guam_rule_filter_groupware:new(Config), ServerConfig = kolab_guam_sup:default_imap_server_config(), { ok, ImapSession } = eimap:start_link(ServerConfig), %% create the rule, ready for testing ClientData = <<"7 list (subscribed) \"\" \"*\" return (special-use)">>, Split = eimap_utils:split_command_into_components(ClientData), { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(ImapSession, ClientData, Split, State), %% run the dataset through the rule lists:foreach(fun({ Blacklist, Input, Filtered }) -> BlacklistState = ReadyState#state{ blacklist = Blacklist }, { Filtered, _NewState } = kolab_guam_rule_filter_groupware:apply_to_server_message(ImapSession, Input, BlacklistState) end, Data). kolab_guam_rule_filter_groupware_responsefiltering_multipacket_test(_TestConfig) -> %% Data to be fed into the test, one tuple per iteration %% Tuple format: { [ input_packets ] = complete_message, correct_output } Data = [ { [ {<<"Calendar">>, <<"Calendar/">>}, {<<"Calendar/Personal Calendar">>, <<"Calendar/Personal Calendar/">>}, {<<"Configuration">>, <<"Configuration/">>}, {<<"Contacts">>, <<"Contacts/">>}, {<<"Contacts/Personal Contacts">>, <<"Contacts/Personal Contacts/">>}, {<<"Files">>, <<"Files/">>}, {<<"Journal">>, <<"Journal/">>}, {<<"Notes">>, <<"Notes/">>}, {<<"Tasks">>, <<"Tasks/">>} ], [ <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Calendar\r\n* LIST (\\Subscribed) \"/\" \"Calendar/Personal Calendar\"\r\n* LIST (\\Subscribed) \"/\" Configuration\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Contacts\r\n* LIST (\\Subscribed) \"/\" \"Contacts/Personal Contacts\"\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Files\r\n* LIST (\\Subscribed) \"/\" Journal\r\n* LIST (\\Subscribed)">>, <<"\"/\" Notes\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Tasks\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> ], <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> } ], %% setup boilerplate Config = {}, %%TODO? State = kolab_guam_rule_filter_groupware:new(Config), ServerConfig = kolab_guam_sup:default_imap_server_config(), { ok, ImapSession } = eimap:start_link(ServerConfig), %% create the rule, ready for testing ClientData = <<"7 list (subscribed) \"\" \"*\" return (special-use)">>, Split = eimap_utils:split_command_into_components(ClientData), { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(ImapSession, ClientData, Split, State), %% run the dataset through the rule lists:foreach(fun({ Blacklist, Input, Filtered }) -> BlacklistState = ReadyState#state{ blacklist = Blacklist }, Filtered = filter_groupware_packets(ImapSession, BlacklistState, Input, <<>>) end, Data). filter_groupware_packets(_ImapSession, _ReadyState, [], Buffer) -> Buffer; filter_groupware_packets(ImapSession, ReadyState, [Input|More], Buffer) -> { Processed, State } = kolab_guam_rule_filter_groupware:apply_to_server_message(ImapSession, Input, ReadyState), filter_groupware_packets(ImapSession, State, More, <>). diff --git a/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl b/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl index f4ed533..9504406 100644 --- a/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl +++ b/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl @@ -1,66 +1,78 @@ %% Copyright 2015 Kolab Systems AG (http://www.kolabsys.com) %% %% Aaron Seigo (Kolab Systems) %% %% This program is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% (at your option) any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program. If not, see . -module(kolab_guam_sup_SUITE). % easier than exporting by name -compile(export_all). % required for common_test to work --include("ct.hrl"). +-include_lib("common_test/include/ct.hrl"). %%%%%%%%%%%%%%%%%%%%%%%%%%% %% common test callbacks %% %%%%%%%%%%%%%%%%%%%%%%%%%%% % Specify a list of all unit test functions all() -> [default_imap_server_config_test, imap_server_config_test]. % required, but can just return Config. this is a suite level setup function. init_per_suite(Config) -> - application:load(kolab_guam), + application:set_env(kolab_guam, imap_servers, [ + { default, [ + { host, "192.168.56.102" }, + { port, 994 }, + { tls, true } + ] + }, + { test_default, [ + { host, "192.168.56.101" }, + { port, 993 }, + { tls, false } + ] + } + ] + ), Config. % required, but can just return Config. this is a suite level tear down function. end_per_suite(Config) -> Config. % optional, can do function level setup for all functions, % or for individual functions by matching on TestCase. init_per_testcase(_TestCase, Config) -> Config. % optional, can do function level tear down for all functions, % or for individual functions by matching on TestCase. end_per_testcase(_TestCase, Config) -> Config. -% c("apps/kolab_guam/test/kolab_guam_sup_tests.erl"). eunit:test(kolab_guam_sup_tests). - default_imap_server_config_test(_TestConfig) -> Expected = [ { host, "192.168.56.102" }, { port, 994 }, { tls, true } ], Expected = kolab_guam_sup:default_imap_server_config(). imap_server_config_test(_TestConfig) -> Configs = [ { test_default, [ { host, "192.168.56.101" }, { port, 993 }, { tls, false } ] } ], lists:foreach(fun({ Config, Record }) -> Record = kolab_guam_sup:imap_server_config(Config) end, Configs).