ct_telnet

Common Test specific layer on top of telnet client ct_telnet_client.erl.

Common Test specific layer on top of telnet client ct_telnet_client.erl

Use this module to set up telnet connections, send commands and
perform string matching on the result.
See the unix_telnet manual page for information about how to use
ct_telnet, and configure connections, specifically for unix hosts.

Enter the telnet_settings term in a configuration
file included in the test and ct_telnet will retrieve the information
automatically. Note that keep_alive may be specified per connection if
required. See unix_telnet for details.

The target data must exist in a configuration file. The connection
may be associated with either Name and/or the returned
Handle. To allocate a name for the target,
use ct:require/2 in a test case, or use a
require statement in the suite info function
(suite/0), or in a test case info function.
If you want the connection to be associated with Handle only
(in case you need to open multiple connections to a host for example),
simply use Key, the configuration variable name, to
specify the target. Note that a connection that has no associated target
name can only be closed with the handle value.

TargetMod is a module which exports the functions
connect(Ip,Port,KeepAlive,Extra) and get_prompt_regexp()
for the given TargetType (e.g. unix_telnet).

Pattern can be a POSIX regular expression. If more
than one pattern is given, the function returns when the first
match is found.

RxMatch is a list of matched strings. It looks
like this: [FullMatch, SubMatch1, SubMatch2, ...]
where FullMatch is the string matched by the whole
regular expression and SubMatchN is the string that
matched subexpression no N. Subexpressions are
denoted with '(' ')' in the regular expression

If a Tag is given, the returned Match
will also include the matched Tag. Else, only
RxMatch is returned.

The function will always return when a prompt is found, unless
the ignore_prompt options is used.

The timeout option indicates that the function
shall return if the telnet client is idle (i.e. if no data is
received) for more than Timeout milliseconds. Default
timeout is 10 seconds.

The repeat option indicates that the pattern(s)
shall be matched multiple times. If N is given, the
pattern(s) will be matched N times, and the function
will return with HaltReason = done.

The sequence option indicates that all patterns
shall be matched in a sequence. A match will not be concluded
untill all patterns are matched.

Both repeat and sequence can be
interrupted by one or more HaltPatterns. When
sequence or repeat is used, there will
always be a MatchList returned, i.e. a list of
Match instead of only one Match. There
will also be a HaltReason returned.

Examples:expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[sequence,{halt,[{nnn,"NNN"}]}]). will try to match
"ABC" first and then "XYZ", but if "NNN" appears the function will
return {error,{nnn,["NNN"]}}. If both "ABC" and "XYZ"
are matched, the function will return
{ok,[AbcMatch,XyzMatch]}.

expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[{repeat,2},{halt,[{nnn,"NNN"}]}]). will try to match
"ABC" or "XYZ" twice. If "NNN" appears the function will return
with HaltReason = {nnn,["NNN"]}.

The repeat and sequence options can be
combined in order to match a sequence multiple times.