File: 30_autopage.t

package info (click to toggle)
net-telnet-cisco 1.10-5.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 160 kB
  • ctags: 32
  • sloc: perl: 792; makefile: 52
file content (80 lines) | stat: -rw-r--r-- 2,078 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- perl -*-

use Test::More tests => 11;
use Net::Telnet::Cisco;
use FindBin;
use Carp;
use t::Utils;

my %G = load();
my $S;

SKIP: {
    skip("Router unknown", 1) 		unless $G{ROUTER};
    skip("Login or password unknown", 1)	unless $G{LOGIN} || $G{PASSWD};

    ok $S = Net::Telnet::Cisco->new( Errmode	 => \&confess,
				     Host	 => $G{ROUTER},
				    log_args(),
				   ),				"new()";
}

SKIP: {
    skip("No Net::Telnet::Cisco session", 9) unless $S;

    ok $S->login(Name     => $G{LOGIN},
		 Password => $G{PASSWD},
		 Passcode => $G{PASSCODE},),			"login()";

    ok $S->autopage,		       				"autopage() on";
    my @out = $S->cmd('show ver');
    unlike $out[-1], '/--More--/',				"autopage() last line";
    unlike $S->last_prompt, '/--More--/',				"autopage() last prompt";

    my %logs = log_args();
    open LOG, "< $logs{Input_log}" or die "Can't open log: $!";
    my $log = join "", <LOG>;
    close LOG;

    # Remove last prompt, which isn't present in @out
    $log =~ s/\cJ\cJ.*\Z//m;

    # Strip ^Hs from log
    $log = Net::Telnet::Cisco::_normalize($log);
    is my $count = ($log =~ tr/\cH//), 0,			"_normalize()";

    # get rid of "show ver" line and turn @out into a string.
    shift @out;
    my $out = join "", @out;
    $out =~ s/\cJ\cJ.*\Z//m;

    my $i = index $log, $out;
    is $i + length $out, length $log,				"autopage() 1.09 bugfix";

    # Turn off autopaging. We should timeout with a More prompt
    # on the last line.
    is $S->autopage(0), 0,					"autopage() off";

    # Turn off error handling; we *want* to time-out now.
    $S->errmode('return');
    $S->errmsg('');

    show_help($S, -Timeout => 1);
    ok $S->timed_out,						"timed_out()";
    like $S->errmsg, '/timed-out/',				"autopage() not called";
    ok $S->cmd("\b" x 6),				 	"show ? cleanup";

    # Restore error handling
    $S->errmode(\&confess);

    # Cancel out of the "show interfaces"
    $S->cmd("\cZ");

    $S->close;
}

END {
   cleanup(savelogs => $G{SAVELOGS},
		   failed => scalar grep {$_ == 0} Test::More->builder->summary,
		  );
};