riak / src / jiak_default_tests.erl

Bryan Fink 814c2a7 

Bryan Fink 0b02326 
Bryan Fink 814c2a7 

%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License.  You may obtain
%% a copy of the License at

%%   http://www.apache.org/licenses/LICENSE-2.0

%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.    

%% @doc Tests for jiak_default.  Parameterized modules must
%%      have their eunit tests in a separate file.


static_props_test_() ->
    M = jiak_default:new(
          [{allowed_fields,  [foo, bar, baz, quux]},
           {required_fields, [foo, bar]},
           {read_mask,       [foo, bar, baz]},
           {write_mask,      [foo]}]),
    {"Static Properties",
     [{"init", ?_assertEqual({ok, context_ignored},
                             M:init(key_ignored, context_ignored))},
      {"auth_ok", ?_assertEqual({true, reqdata_ignored, context_ignored},
                                M:auth_ok(key_ignored, reqdata_ignored,
      {"bucket_listable", ?_assert(M:bucket_listable())},
      {"allowed_fields", ?_assertEqual([foo, bar, baz, quux],
      {"required_fields", ?_assertEqual([foo, bar],
      {"read_mask", ?_assertEqual([foo, bar, baz], M:read_mask())},
      {"write_mask", ?_assertEqual([foo], M:write_mask())}

expires_test_() ->
     [{"default", ?_assertEqual({600, reqdata_ignored, context_ignored},
                                  key_ignored, reqdata_ignored,
          {10, reqdata_ignored, context_ignored},
          (jiak_default:new([{expiry_seconds, 10}])):expires_in_seconds(
           key_ignored, reqdata_ignored, context_ignored))}

write_test_() ->
    M = jiak_default:new([]),
    O = jiak_object:new(<<"bucket_ignored">>, <<"key_ignored">>),
    {"*_write functions",
          {{ok, O}, reqdata_ignored, context_ignored},
          M:check_write({type_ignored, key_ignored}, O,
                        reqdata_ignored, context_ignored))},
          {{ok, O}, reqdata_ignored, context_ignored},
          M:effect_write({type_ignored, key_ignored}, O,
                         reqdata_ignored, context_ignored))},
          {ok, reqdata_ignored, context_ignored},
          M:after_write(key_ignored, O,
                        reqdata_ignored, context_ignored))}

sibling_test() ->
    M = jiak_default:new([]),
    A = {dict:store(<<"X-Riak-Last-Modified">>,
                    dict:store(a, a, dict:new())),
         {{struct, [{a,a}]},
    B = {dict:store(<<"X-Riak-Last-Modified">>,
                    dict:store(b, b, dict:new())),
         {{struct, [{b,b}]},
    {CM, {{struct, CO}, CL}} = M:merge_siblings([A,B]),

    ?assertEqual(3, dict:size(CM)),
    ?assertEqual([a,b], [ dict:fetch(P, CM) || P <- [a,b] ]),
    ?assertEqual(2, length(CO)),
    ?assertEqual([a,b], [ proplists:get_value(P, CO) || P <- [a,b] ]),
    ?assertEqual(2, length(CL)),
    ?assert(lists:all(fun(L) -> lists:member(L, CL) end, [a,b])).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.