Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Adds a test suite for logplex channel token cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
archaelus committed May 6, 2013
1 parent 3c5e665 commit ee8d507
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/logplex_channel_SUITE.erl
@@ -0,0 +1,65 @@
%%%-------------------------------------------------------------------
%% @copyright You, 2036
%% @author You <erlanghacker@example.com>
%% @doc CommonTest test suite for logplex_channel
%% @end
%%%-------------------------------------------------------------------

-module(logplex_channel_SUITE).
-include_lib("common_test/include/ct.hrl").
-compile(export_all).

%%%%%%%%%%%%%%%%%%%%
%%% Tests to run %%%
%%%%%%%%%%%%%%%%%%%%
%% Specific test cases or groups to run. The test case is named as
%% a single atom.

all() ->
[token_caching].

%%%%%%%%%%%%%%%%%%%%%%
%%% Setup/Teardown %%%
%%%%%%%%%%%%%%%%%%%%%%
%% Runs once at the beginning of the suite. The process is different
%% from the one the case will run in.
init_per_suite(Config) ->
Config.

%% Runs once at the end of the suite. The process is different
%% from the one the case will run in.
end_per_suite(Config) ->
Config.

%% Runs before the test case. Runs in the same process.
init_per_testcase(token_caching, Config) ->
logplex_channel:create_ets_table(),
Config;
init_per_testcase(_CaseName, Config) ->
Config.

%% Runs after the test case. Runs in the same process.
end_per_testcase(_CaseName, Config) ->
ets:delete(channels),
Config.

%%%%%%%%%%%%%
%%% TESTS %%%
%%%%%%%%%%%%%

token_caching(_Config) ->
ChannelId = 1,
Chan0 = logplex_channel:new(ChannelId, <<"Test channel">>),
[] = logplex_channel:tokens(Chan0),
logplex_channel:cache(Chan0),
Token = logplex_token:new(logplex_token:new_unique_token_id(), ChannelId),
Chan1 = logplex_channel:cache_token(ChannelId, Token),
Chan1 = logplex_channel:lookup(ChannelId),
Token = logplex_channel:has_token(logplex_token:id(Token), Chan1),
[Token] = logplex_channel:lookup_tokens(ChannelId),
Chan1 = logplex_channel:cache_token(ChannelId, Token),
Token = logplex_channel:has_token(logplex_token:id(Token), Chan1),
Token2 = logplex_token:new(logplex_token:new_unique_token_id(), ChannelId),
logplex_channel:cache_token(ChannelId, Token2),
Token2 = logplex_channel:has_token(logplex_token:id(Token2), Chan1),
ok.

0 comments on commit ee8d507

Please sign in to comment.