-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPOOL-197] - [#111] - Improve test coverage, error message
* Fixed formatting in error message * Added eunit tests for oc_chef_authz_acl * Updates for code review comments. Signed-off-by: Marc Paradise <[email protected]>
- Loading branch information
Marc Paradise
committed
Aug 22, 2016
1 parent
d7457ad
commit 1f1d20b
Showing
6 changed files
with
98 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/oc_erchef/apps/oc_chef_authz/test/oc_chef_authz_acl_tests.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil; fill-column: 92-*- | ||
%% ex: ts=4 sw=4 et | ||
%% | ||
%% @author Marc A. Paradise <[email protected]> | ||
%% Copyright 2016 Chef Software, Inc. | ||
%% | ||
%% 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 | ||
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
%% KIND, either express or implied. See the License for the | ||
%% specific language governing permissions and limitations | ||
%% under the License. | ||
%% | ||
-module(oc_chef_authz_acl_tests). | ||
|
||
-compile([export_all]). | ||
|
||
-include_lib("eunit/include/eunit.hrl"). | ||
fetch_actors_test_() -> | ||
{foreach, | ||
fun() -> | ||
meck:new(oc_chef_authz_db) | ||
end, | ||
fun(_) -> meck:unload([oc_chef_authz_db]) end, | ||
[ | ||
{"bad_actor: actors that have neither client nor user authz ids", | ||
fun() -> | ||
meck:expect(oc_chef_authz_db, find_org_actors_by_name, | ||
fun invalid_actor_data_response/2), | ||
FetchActorResponse = oc_chef_authz_acl:fetch_actors(<<"any">>, | ||
[<<"bob">>, <<"jane">>]), | ||
?assertEqual({error, {bad_actor, [<<"bob">>, <<"jane">>]}}, FetchActorResponse) | ||
end}, | ||
{"ambiguous_actor: actors that have both user and client authz ids", | ||
fun() -> | ||
meck:expect(oc_chef_authz_db, find_org_actors_by_name, | ||
fun ambiguous_actor_data_response/2), | ||
FetchActorResponse = oc_chef_authz_acl:fetch_actors(<<"any">>, [<<"bob">>, <<"jane">>]), | ||
?assertEqual({error, {ambiguous_actor, [<<"bob">>, <<"jane">>]}}, FetchActorResponse) | ||
end}, | ||
{"ok: actors that have only a client authz id", | ||
fun() -> | ||
meck:expect(oc_chef_authz_db, find_org_actors_by_name, | ||
fun valid_client_data_response/2), | ||
FetchActorResponse = oc_chef_authz_acl:fetch_actors(<<"any">>, [<<"bob">>, <<"jane">>]), | ||
?assertEqual({ok, [<<"id-a">>, <<"id-a">>]}, FetchActorResponse) | ||
end}, | ||
{"ok: actors that have only a user authz id", | ||
fun() -> | ||
meck:expect(oc_chef_authz_db, find_org_actors_by_name, | ||
fun valid_user_data_response/2), | ||
FetchActorResponse = oc_chef_authz_acl:fetch_actors(<<"any">>, [<<"bob">>, <<"jane">>]), | ||
?assertEqual({ok, [<<"id-a">>, <<"id-a">>]}, FetchActorResponse) | ||
end} | ||
]}. | ||
|
||
valid_user_data_response(_, Names) -> | ||
{ok, [{N, null, <<"id-a">>} || N <- Names]}. | ||
|
||
valid_client_data_response(_, Names) -> | ||
{ok, [{N, <<"id-a">>, null} || N <- Names]}. | ||
|
||
invalid_actor_data_response(_, Names) -> | ||
{ok, [{N, null, null} || N <- Names]}. | ||
|
||
ambiguous_actor_data_response(_, Names) -> | ||
{ok, [{N, <<"id1">>, <<"id2">>} || N <- Names]}. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters