mirror of
https://github.com/valitydev/dmt-client.git
synced 2024-11-06 09:25:16 +00:00
68 lines
1.9 KiB
Erlang
68 lines
1.9 KiB
Erlang
-module(dmt_client_tests_SUITE).
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
-export([all/0]).
|
|
-export([groups/0]).
|
|
-export([init_per_suite/1]).
|
|
-export([end_per_suite/1]).
|
|
-export([application_stop/1]).
|
|
-export([poll/1]).
|
|
|
|
-include_lib("dmsl/include/dmsl_domain_config_thrift.hrl").
|
|
|
|
%%
|
|
%% tests descriptions
|
|
%%
|
|
-spec all() -> [term()].
|
|
all() ->
|
|
[
|
|
{group, basic_lifecycle}
|
|
].
|
|
|
|
-spec groups() -> [term()].
|
|
groups() ->
|
|
[
|
|
{basic_lifecycle, [sequence], [
|
|
poll
|
|
]}
|
|
].
|
|
|
|
%%
|
|
%% starting/stopping
|
|
-spec init_per_suite(term()) -> term().
|
|
init_per_suite(C) ->
|
|
{ok, Apps} = application:ensure_all_started(dmt_client),
|
|
[{apps, Apps}|C].
|
|
|
|
-spec end_per_suite(term()) -> term().
|
|
end_per_suite(C) ->
|
|
[application_stop(App) || App <- proplists:get_value(apps, C)].
|
|
|
|
-spec application_stop(term()) -> term().
|
|
application_stop(App) ->
|
|
application:stop(App).
|
|
|
|
%%
|
|
%% tests
|
|
-spec poll(term()) -> term().
|
|
poll(_C) ->
|
|
Object = fixture_domain_object(1, <<"InsertFixture">>),
|
|
Ref = fixture_object_ref(1),
|
|
object_not_found = (catch dmt_client:checkout_object({head, #'Head'{}}, Ref)),
|
|
#'Snapshot'{version = Version1} = dmt_client:checkout({head, #'Head'{}}),
|
|
Version2 = dmt_client_api:commit(Version1, #'Commit'{ops = [{insert, #'InsertOp'{object = Object}}]}),
|
|
true = Version1 < Version2,
|
|
%% TODO: replace with sleep(genlib_app:env(dmt_client, poll_interval))
|
|
{ok, _} = dmt_client_poller:poll(),
|
|
#'Snapshot'{version = Version2} = dmt_client:checkout({head, #'Head'{}}),
|
|
#'VersionedObject'{object = Object} = dmt_client:checkout_object({head, #'Head'{}}, Ref).
|
|
|
|
fixture_domain_object(Ref, Data) ->
|
|
{category, #'domain_CategoryObject'{
|
|
ref = #'domain_CategoryRef'{id = Ref},
|
|
data = #'domain_Category'{name = Data, description = Data}
|
|
}}.
|
|
|
|
fixture_object_ref(Ref) ->
|
|
{category, #'domain_CategoryRef'{id = Ref}}.
|