[erlang-questions] ct_telnet example

Peter Andersson <>
Tue Aug 3 17:31:48 CEST 2010


Hi Luc,

Here's an example suite for you:

suite() ->
    [{require, host},
     {require, telnet_conn, host},
     {default_config, host, [{telnet,"myhost"},
                             {username,"tester"},
                             {password,"letmein"}]}].    

all() -> [global, multiple, simple].

%% open a connection with a registered name (telnet_conn)
init_per_testcase(global, Config) ->
    {ok,_} = ct_telnet:open(telnet_conn, telnet, unix_telnet),
    Config;

%% open multiple connections (no connection name specified)
init_per_testcase(multiple, Config) ->
    {ok,H1} = ct_telnet:open(host, telnet, unix_telnet),
    {ok,H2} = ct_telnet:open(host, telnet, unix_telnet),
    [{handles,[H1,H2]}|Config];

init_per_testcase(_, Config) ->
    Config.

end_per_testcase(global, _Config) ->
    ok = ct_telnet:close(telnet_conn);

end_per_testcase(multiple, Config) ->
    [ok = ct_telnet:close(H) ||
        H <- proplists:get_value(handles, Config)],
    ok;

end_per_testcase(_, _) ->
    ok.

global(_) ->
    {ok,_Result} = ct_telnet:cmd(telnet_conn, "ls"),
    ok.

multiple(Config) ->
    [{ok,_Result} = ct_telnet:cmd(H, "ls") ||
        H <- proplists:get_value(handles, Config)],
    ok.

%% with alias name == callback module, a registered connection can
%% be opened with ct_telnet:open/1

simple() ->
    [{require, unix_telnet, unix},
     {default_config, unix, [{telnet,"myhost"},
                             {username,"tester"},
                             {password,"letmein"}]}].

simple(_) ->
    {ok,_} = ct_telnet:open(unix_telnet),
    {ok,_Result} = ct_telnet:cmd(unix_telnet, "ls"),
    ct_telnet:close(unix_telnet),
    ok.


  /Peter

Ericsson AB, Erlang/OTP


Luc Evers wrote:
>    Hi,
>
>   I'm looking for an example using the ct_telnet module.
>
>
>   Thanks!
>
>    Luc.
>
>   



More information about the erlang-questions mailing list