Merge branch 'rabbitmq-management-528'
This commit is contained in:
commit
09f26a3243
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(rabbit_data_coercion).
|
||||
|
||||
-export([to_binary/1, to_list/1, to_atom/1, to_integer/1]).
|
||||
-export([to_binary/1, to_list/1, to_atom/1, to_integer/1, to_proplist/1, to_map/1]).
|
||||
-export([to_atom/2]).
|
||||
|
||||
-spec to_binary(Val :: binary() | list() | atom() | integer()) -> binary().
|
||||
|
|
@ -45,3 +45,11 @@ to_atom(Val, Encoding) when is_binary(Val) -> binary_to_atom(Val, Encoding).
|
|||
to_integer(Val) when is_integer(Val) -> Val;
|
||||
to_integer(Val) when is_list(Val) -> list_to_integer(Val);
|
||||
to_integer(Val) when is_binary(Val) -> binary_to_integer(Val).
|
||||
|
||||
-spec to_proplist(Val :: map() | list()) -> list().
|
||||
to_proplist(Val) when is_list(Val) -> Val;
|
||||
to_proplist(Val) when is_map(Val) -> maps:to_list(Val).
|
||||
|
||||
-spec to_map(Val :: map() | list()) -> map().
|
||||
to_map(Val) when is_map(Val) -> Val;
|
||||
to_map(Val) when is_list(Val) -> maps:from_list(Val).
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
-include_lib("proper/include/proper.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-include("rabbit_memory.hrl").
|
||||
|
||||
|
|
@ -33,6 +34,8 @@ all() ->
|
|||
groups() ->
|
||||
[
|
||||
{parallel_tests, [parallel], [
|
||||
data_coercion_to_proplist,
|
||||
data_coercion_to_map,
|
||||
encrypt_decrypt,
|
||||
encrypt_decrypt_term,
|
||||
version_equivalence,
|
||||
|
|
@ -281,6 +284,14 @@ platform_and_version(_Config) ->
|
|||
_ -> ok
|
||||
end.
|
||||
|
||||
data_coercion_to_map(_Config) ->
|
||||
?assertEqual(#{a => 1}, rabbit_data_coercion:to_map([{a, 1}])),
|
||||
?assertEqual(#{a => 1}, rabbit_data_coercion:to_map(#{a => 1})).
|
||||
|
||||
data_coercion_to_proplist(_Config) ->
|
||||
?assertEqual([{a, 1}], rabbit_data_coercion:to_proplist([{a, 1}])),
|
||||
?assertEqual([{a, 1}], rabbit_data_coercion:to_proplist(#{a => 1})).
|
||||
|
||||
pid_decompose_compose(_Config) ->
|
||||
Pid = self(),
|
||||
{Node, Cre, Id, Ser} = rabbit_misc:decompose_pid(Pid),
|
||||
|
|
|
|||
Loading…
Reference in New Issue