Skip to content

Commit 6285ada

Browse files
committed
Augment tests
1 parent 0069dc6 commit 6285ada

File tree

1 file changed

+62
-33
lines changed

1 file changed

+62
-33
lines changed

lib/kernel/test/inet_res_SUITE.erl

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,34 @@ init_per_testcase(Func, Config) ->
161161
DataDir = proplists:get_value(data_dir, Config),
162162
try ns_init(zone_dir(Func), PrivDir, DataDir) of
163163
NsSpec ->
164-
?P("init_per_testcase -> get resolver lookup"),
165-
Lookup = inet_db:res_option(lookup),
166-
?P("init_per_testcase -> set file:dns"),
167-
inet_db:set_lookup([file,dns]),
168-
case NsSpec of
169-
{_,{IP,Port},_} ->
170-
?P("init_per_testcase -> insert alt nameserver ~p:~w",
171-
[IP, Port]),
172-
inet_db:ins_alt_ns(IP, Port);
173-
_ -> ok
174-
end,
164+
UpdatedConfig =
165+
[{nameserver, NsSpec}] ++
166+
case Func of
167+
basic ->
168+
Config;
169+
_ ->
170+
?P("init_per_testcase -> get resolver lookup"),
171+
Lookup = inet_db:res_option(lookup),
172+
?P("init_per_testcase -> set file:dns"),
173+
inet_db:set_lookup([file,dns]),
174+
case NsSpec of
175+
{_,{IP,Port},_} ->
176+
?P("init_per_testcase -> "
177+
"insert alt nameserver ~p:~w",
178+
[IP, Port]),
179+
inet_db:ins_alt_ns(IP, Port);
180+
_ -> ok
181+
end,
182+
?P("init_per_testcase -> saved"
183+
"~n Lookup: ~p", [Lookup]),
184+
[{res_lookup, Lookup} | Config]
185+
end,
175186
%% dbg:tracer(),
176187
%% dbg:p(all, c),
177188
%% dbg:tpl(inet_res, query_nss_res, cx),
178189
?P("init_per_testcase -> done:"
179-
"~n NsSpec: ~p"
180-
"~n Lookup: ~p", [NsSpec, Lookup]),
181-
[{nameserver, NsSpec}, {res_lookup, Lookup} | Config]
190+
"~n NsSpec: ~p", [NsSpec]),
191+
UpdatedConfig
182192
catch
183193
SkipReason ->
184194
?P("init_per_testcase -> skip: ~p", [SkipReason]),
@@ -190,17 +200,21 @@ init_per_testcase(Func, Config) ->
190200
end.
191201

192202
end_per_testcase(_Func, Config) ->
193-
inet_db:set_lookup(proplists:get_value(res_lookup, Config)),
194203
NsSpec = proplists:get_value(nameserver, Config),
195-
case NsSpec of
196-
{_,{IP,Port},_} ->
197-
inet_db:del_alt_ns(IP, Port);
198-
_ -> ok
204+
case proplists:lookup(res_lookup, Config) of
205+
none ->
206+
ok;
207+
{res_lookup, Lookup} ->
208+
inet_db:set_lookup(Lookup),
209+
case NsSpec of
210+
{_,{IP,Port},_} ->
211+
inet_db:del_alt_ns(IP, Port);
212+
_ -> ok
213+
end
199214
end,
200215
%% dbg:stop(),
201216
ns_end(NsSpec, proplists:get_value(priv_dir, Config)).
202217

203-
204218
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205219
%% Nameserver control
206220

@@ -528,14 +542,16 @@ proxy_ns({proxy,_,_,ProxyNS}) -> ProxyNS.
528542
basic(Config) when is_list(Config) ->
529543
?P("begin"),
530544
NS = ns(Config),
545+
NSs = [NS],
546+
Options = [{nameservers,NSs},verbose],
531547
Name = "ns.otptest",
532548
NameC = caseflip(Name),
533549
NameD = NameC ++ ".",
534550
IP1 = {127,0,0,253},
535551
IP2 = {127,0,0,254},
536552
%%
537553
%% nslookup
538-
{ok,Msg1} = inet_res:nslookup(Name, in, a, [NS]),
554+
{ok,Msg1} = inet_res:nslookup(Name, in, a, NSs),
539555
?P("nslookup with ~p: ~n ~p", [Name, Msg1]),
540556
[RR1, RR2] = lists:sort(inet_dns:msg(Msg1, anlist)),
541557
IP1 = inet_dns:rr(RR1, data),
@@ -544,7 +560,7 @@ basic(Config) when is_list(Config) ->
544560
%%io:format("Bin1 = ~w~n", [Bin1]),
545561
{ok,Msg1} = inet_dns:decode(Bin1),
546562
%% Now with scrambled case
547-
{ok,Msg1b} = inet_res:nslookup(NameC, in, a, [NS]),
563+
{ok,Msg1b} = inet_res:nslookup(NameC, in, a, NSs),
548564
?P("nslookup with ~p: ~n ~p", [NameC, Msg1b]),
549565
[RR1b, RR2b] = lists:sort(inet_dns:msg(Msg1b, anlist)),
550566
IP1 = inet_dns:rr(RR1b, data),
@@ -560,7 +576,7 @@ basic(Config) when is_list(Config) ->
560576
=:= tolower(inet_dns:rr(RR2b, domain))),
561577
%%
562578
%% resolve
563-
{ok,Msg2} = inet_res:resolve(Name, in, a, [{nameservers,[NS]},verbose]),
579+
{ok,Msg2} = inet_res:resolve(Name, in, a, Options),
564580
?P("resolve with ~p: ~n ~p", [Name, Msg2]),
565581
[RR1c, RR2c] = lists:sort(inet_dns:msg(Msg2, anlist)),
566582
IP1 = inet_dns:rr(RR1c, data),
@@ -569,7 +585,7 @@ basic(Config) when is_list(Config) ->
569585
%%io:format("Bin2 = ~w~n", [Bin2]),
570586
{ok,Msg2} = inet_dns:decode(Bin2),
571587
%% Now with scrambled case
572-
{ok,Msg2b} = inet_res:resolve(NameC, in, a, [{nameservers,[NS]},verbose]),
588+
{ok,Msg2b} = inet_res:resolve(NameC, in, a, Options),
573589
?P("resolve with ~p: ~n ~p", [NameC, Msg2b]),
574590
[RR1d, RR2d] = lists:sort(inet_dns:msg(Msg2b, anlist)),
575591
IP1 = inet_dns:rr(RR1d, data),
@@ -585,10 +601,10 @@ basic(Config) when is_list(Config) ->
585601
=:= tolower(inet_dns:rr(RR2d, domain))),
586602
?P("resolve \"127.0.0.1\"~n", []),
587603
{ok, Msg3} =
588-
inet_res:resolve("127.0.0.1", in, a, [{nameservers,[NS]},verbose]),
604+
inet_res:resolve("127.0.0.1", in, a, Options),
589605
[] = inet_dns:msg(Msg3, anlist),
590606
{ok, Msg4} =
591-
inet_res:resolve("127.0.0.1", in, ptr, [{nameservers,[NS]},verbose]),
607+
inet_res:resolve("127.0.0.1", in, ptr, Options),
592608
[RR4] = inet_dns:msg(Msg4, anlist),
593609
"1.0.0.127.in-addr.arpa" = inet_dns:rr(RR4, domain),
594610
"test1-78901234567890123456789012345678.otptest" =
@@ -598,28 +614,41 @@ basic(Config) when is_list(Config) ->
598614
?P("lookup"),
599615
[IP1, IP2] =
600616
lists:sort(
601-
inet_res:lookup(Name, in, a, [{nameservers,[NS]},verbose])),
617+
inet_res:lookup(Name, in, a, Options)),
602618
[IP1, IP2] =
603619
lists:sort(
604-
inet_res:lookup(NameC, in, a, [{nameservers,[NS]},verbose])),
620+
inet_res:lookup(NameC, in, a, Options)),
605621
[IP1, IP2] =
606622
lists:sort(
607-
inet_res:lookup(NameD, in, a, [{nameservers,[NS]},verbose])),
623+
inet_res:lookup(NameD, in, a, Options)),
608624
%%
609625
%% gethostbyname
610626
?P("gethostbyname"),
611-
{ok,#hostent{h_addr_list=IPs1}} = inet_res:gethostbyname(Name),
627+
{ok,#hostent{h_addr_list=IPs1}} =
628+
inet_res:gethostbyname(Name, inet, Options, infinity),
612629
[IP1, IP2] = lists:sort(IPs1),
613-
{ok,#hostent{h_addr_list=IPs2}} = inet_res:gethostbyname(NameC),
630+
{ok,#hostent{h_addr_list=IPs2}} =
631+
inet_res:gethostbyname(NameC, inet, Options, infinity),
614632
[IP1, IP2] = lists:sort(IPs2),
615633
%%
616634
%% getbyname
617635
?P("getbyname"),
618-
{ok,#hostent{h_addr_list=IPs3}} = inet_res:getbyname(Name, a),
636+
{ok,#hostent{h_addr_list=IPs3}} =
637+
inet_res:getbyname(Name, a, Options, infinity),
619638
[IP1, IP2] = lists:sort(IPs3),
620-
{ok,#hostent{h_addr_list=IPs4}} = inet_res:getbyname(NameC, a),
639+
{ok,#hostent{h_addr_list=IPs4}} =
640+
inet_res:getbyname(NameC, a, Options, infinity),
621641
[IP1, IP2] = lists:sort(IPs4),
622642
?P("end"),
643+
%%
644+
%% gethostbyaddr
645+
?P("gethostbyaddr"),
646+
{ok,#hostent{h_name=Name,
647+
h_addr_list=[IP2]}} =
648+
inet_res:gethostbyaddr(IP2, Options, infinity),
649+
{ok,#hostent{h_name=Name,
650+
h_addr_list=[IP1]}} =
651+
inet_res:gethostbyaddr(IP1, Options, infinity),
623652
ok.
624653

625654

0 commit comments

Comments
 (0)