Skip to content

Commit

Permalink
Merge branch 'role-environments'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Falcon committed Aug 29, 2012
2 parents 5729cc3 + 6a240e1 commit b901f8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/chef_role.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-module(chef_role).

-export([
environments/1,
parse_binary_json/2
]).

Expand Down Expand Up @@ -59,6 +60,13 @@

-type role_action() :: create | { update, Name::binary() }.

%% @doc Given the EJSON representation of a role, return a sorted list of the environment names
%% present in the role's `env_run_list` hash.
-spec environments(ej:json_object()) -> [binary()].
environments(Role) ->
{Items} = ej:get({<<"env_run_lists">>}, Role),
lists:sort([ Key || {Key, _} <- Items ]).

%% @doc Convert a binary JSON string representing a Chef Role into an
%% EJson-encoded Erlang data structure.
%% @end
Expand Down
16 changes: 15 additions & 1 deletion test/chef_role_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,23 @@ basic_role() ->
{<<"chef_type">>, <<"role">>},
{<<"default_attributes">>, {[]}},
{<<"override_attributes">>, {[]}},
{<<"run_list">>, []}
{<<"run_list">>, []},
{<<"env_run_lists">>, {[]}}
]}.


role_environments_test_() ->
[{"empty env_run_lists",
?_assertEqual([], chef_role:environments(basic_role()))},

{"non-empty env_run_lists",
fun() ->
Role = ej:set({<<"env_run_lists">>}, basic_role(),
{[{<<"e2">>, {[]}}, {<<"e1">>, {[]}}]}),
?assertEqual([<<"e1">>, <<"e2">>], chef_role:environments(Role))
end}
].

validate_role_test_() ->
[
{"Validate that a role with a missing name is rejected",
Expand Down

0 comments on commit b901f8c

Please sign in to comment.