Merge pull request #87 from rabbitmq/add-topic-unit-test

Add unit test for topic permissions map
This commit is contained in:
Michael Klishin 2017-06-19 19:19:50 +03:00 committed by GitHub
commit f5d94224a7
2 changed files with 54 additions and 20 deletions

View File

@ -1,26 +1,15 @@
# vim:sw=2:et:
# Use a real VM so we can install all the packages we want.
sudo: required
sudo: false
language: erlang
notifications:
email:
- alerts@rabbitmq.com
addons:
apt:
sources:
- sourceline: deb https://packages.erlang-solutions.com/ubuntu precise contrib
key_url: https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
packages:
# Use Elixir from Erlang Solutions. The provided Elixir is
# installed with kiex but is old. By using an prebuilt Debian
# package, we save the compilation time.
- elixir
- xsltproc
otp_release:
- "18.3"
- "19.0"
- "19.3"
before_script:
# The checkout made by Travis is a "detached HEAD" and branches
@ -34,11 +23,12 @@ before_script:
git remote add upstream https://github.com/$TRAVIS_REPO_SLUG.git
git fetch upstream stable:stable || :
git fetch upstream master:master || :
# Remove all kiex installations. This makes sure that the Erlang
# Solutions one is picked: it's after the kiex installations in $PATH.
- echo YES | kiex implode
- kiex selfupdate
- test -x ~/.kiex/elixirs/elixir-1.4.4/bin/elixir || kiex install 1.4.4
- kiex default 1.4.4
script: make tests
cache:
apt: true
directories:
- ~/.kiex/elixirs

View File

@ -29,7 +29,8 @@ all() ->
amqp_uri_accepts_string_and_binaries,
amqp_uri_remove_credentials,
uri_parser_accepts_string_and_binaries,
route_destination_parsing
route_destination_parsing,
rabbit_channel_build_topic_variable_map
].
%% -------------------------------------------------------------------
@ -289,3 +290,46 @@ parse_dest(Destination, Params) ->
rabbit_routing_util:parse_endpoint(Destination, Params).
parse_dest(Destination) ->
rabbit_routing_util:parse_endpoint(Destination).
%% -------------------------------------------------------------------
%% Topic variable map
%% -------------------------------------------------------------------
rabbit_channel_build_topic_variable_map(_Config) ->
AmqpParams = #amqp_params_direct{
adapter_info = #amqp_adapter_info{
additional_info = [
{variable_map, #{<<"client_id">> => <<"client99">>}}]}
},
%% simple case
#{<<"client_id">> := <<"client99">>,
<<"username">> := <<"guest">>,
<<"vhost">> := <<"default">>} = rabbit_channel:build_topic_variable_map(
[{amqp_params, AmqpParams}], <<"default">>, <<"guest">>
),
%% nothing to add
AmqpParams1 = #amqp_params_direct{adapter_info = #amqp_adapter_info{}},
#{<<"username">> := <<"guest">>,
<<"vhost">> := <<"default">>} = rabbit_channel:build_topic_variable_map(
[{amqp_params, AmqpParams1}], <<"default">>, <<"guest">>
),
%% nothing to add with amqp_params_network
AmqpParams2 = #amqp_params_network{},
#{<<"username">> := <<"guest">>,
<<"vhost">> := <<"default">>} = rabbit_channel:build_topic_variable_map(
[{amqp_params, AmqpParams2}], <<"default">>, <<"guest">>
),
%% trying to override channel variables, but those
%% take precedence
AmqpParams3 = #amqp_params_direct{
adapter_info = #amqp_adapter_info{
additional_info = [
{variable_map, #{<<"client_id">> => <<"client99">>,
<<"username">> => <<"admin">>}}]}
},
#{<<"client_id">> := <<"client99">>,
<<"username">> := <<"guest">>,
<<"vhost">> := <<"default">>} = rabbit_channel:build_topic_variable_map(
[{amqp_params, AmqpParams3}], <<"default">>, <<"guest">>
),
ok.