Skip to content
Permalink
Browse files
add eunit test case
  • Loading branch information
DLive committed Apr 24, 2019
1 parent 924e7f7 commit 56759cbda4b3204bdba9c3118e74ce0f5c26a655
Showing 3 changed files with 15 additions and 16 deletions.
@@ -13,7 +13,8 @@
%% API
-export([parse_provider_info/1,gen_provider_info/1]).

%%
parse_provider_info(ProviderStr) when is_binary(ProviderStr)->
parse_provider_info(binary_to_list(ProviderStr));
parse_provider_info(ProviderStr)->
case http_uri:parse(http_uri:decode(ProviderStr),[{scheme_defaults,[{dubbo,20880}]}]) of
{ok, {Scheme, UserInfo, Host, Port, Path, Query}} ->
@@ -32,15 +33,7 @@ parse_provider_info(ProviderStr)->
logger:debug("parse provider error string ~p, error ~p",[ProviderStr,R1]),
{error,R1}
end.
%% PrivoderInfo =list_to_binary(http_uri:decode(binary_to_list(PrivoderStr))),
%% [{ProtocolEndPos,3},{HostEndPos,1},{InterfaceEndPos,1} ] = binary:matches(PrivoderInfo,[<<"://">>,<<"/">>,<<"?">>],[]),
%% HostLength=HostEndPos - ProtocolEndPos-3,
%% InterfaceLenth=InterfaceEndPos-HostEndPos-1,
%% << Protocol:5/binary,_:3/binary,Host:HostLength/binary,_:1/binary,Interface:InterfaceLenth/binary,_:1/binary,Parameter/binary>> = PrivoderInfo,
%% [HostName,Port]=binary:split(Host,<<":">>),
%% ParameterList = binary:split(Parameter,<<"&">>),

%% io:format(user,"protocol end Pos ~p~n protocol:~p~n Host:~p~n Interface:~p~n",[ProtocolEndPos,Protocol,Host,Interface]),

parse_parameter([],Config)->
Config;
@@ -12,11 +12,17 @@
-include_lib("eunit/include/eunit.hrl").
-include("dubbo.hrl").

simple_test() ->
{ok,ProviderConfig} = dubbo_node_config_util:parse_provider_info("..."),
%% io:format(user,"parse config result ~p~n",[ProviderConfig]),
gen_provice_config_test()->
ProviderConfigInfo = dubbo_config_util:gen_provider(<<"defaultApp">>,20880,<<"org.apache.dubbo.test.interface">>,[method1],[]),
ProvideNode = dubbo_node_config_util:gen_provider_info(ProviderConfigInfo),
?assert(is_binary(ProvideNode)).


provider_parse_test() ->
{ok,ProviderConfig} = dubbo_node_config_util:parse_provider_info(<<"dubbo%3A%2F%2F127.0.0.1%3A20880%2Forg.apache.dubbo.test.interface%3Finterface=org.apache.dubbo.test.interface&application=defaultApp&anyhost=true&dubbo=2.5.3&executes=10&methods=method1&side=provider&timestamp=1556095933071">>),
?assertEqual(ProviderConfig#provider_config.protocol,dubbo),
?assertEqual(ProviderConfig#provider_config.host,"192.168.1.6"),
?assertEqual(ProviderConfig#provider_config.host,"127.0.0.1"),
?assertEqual(ProviderConfig#provider_config.port,20880),
?assertEqual(ProviderConfig#provider_config.interface,<<"...">>),
?assertEqual(ProviderConfig#provider_config.interface,<<"org.apache.dubbo.test.interface">>),
?assert(true).

@@ -15,5 +15,5 @@ exist_test() ->
Consumer=#consumer_config{interface = <<"com.ifcoder.demo.facade.User">>,
methods = [<<"a">>,<<"b">>]},
V= dubbo_zookeeper:gen_consumer_node_info(Consumer),
io:format(user,"gen consumer info:~p~n",[V]),
?assert(true).
?debugFmt("consumer info ~p",[V]),
?assert(is_binary(V)).

0 comments on commit 56759cb

Please sign in to comment.