Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3490dcb9d4
Fetching contributors…

Cannot retrieve contributors at this time

file 88 lines (67 sloc) 2.449 kb
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 81 82 83 84 85 86 87 88
#!perl -T
use strict;
use Test::More;


my @oid_list = qw<
.1.3.6.1.4.1.32272.1.1.1.42
.1.3.6.1.4.1.32272.1.1.1.56
.1.3.6.1.4.1.32272.1.1.2.42
.1.3.6.1.4.1.32272.1.1.2.56
.1.3.6.1.4.1.32272.1.1.3.42
.1.3.6.1.4.1.32272.1.1.3.56

.1.3.6.1.4.1.32272.2.1.1.42
.1.3.6.1.4.1.32272.2.1.1.56
.1.3.6.1.4.1.32272.2.1.2.42
.1.3.6.1.4.1.32272.2.1.2.56

.1.3.6.1.4.1.32272.3.1.1.42
.1.3.6.1.4.1.32272.3.1.1.56
.1.3.6.1.4.1.32272.3.1.2.42
.1.3.6.1.4.1.32272.3.1.2.56
.1.3.6.1.4.1.32272.3.1.3.42
.1.3.6.1.4.1.32272.3.1.3.56
>;

my $base_oid = ".1.3.6.1.4.1.32272";
my $walk_base = "$base_oid.2";
my @context = grep /^$walk_base/, @oid_list;

my @cases = (
    [ "called with no request and no context",
        [], $oid_list[0] ],

    [ "called with no request, but with a context",
        [ "", $walk_base ], $oid_list[6] ],

    [ "called with a request within the list, with no context",
        [ "$base_oid.3" ], $oid_list[10] ],

    [ "called with a request within the list, with no context",
        [ $oid_list[4] ], $oid_list[5] ],

    [ "called with a request outside the list, with no context",
        [ "$base_oid.5" ], "NONE" ],

    [ "called with a request within the list, before the context",
        [ "$base_oid.1", $walk_base ], "NONE" ],

    [ "called with a request within the list, within the context",
        [ "$base_oid.2", $walk_base ], $oid_list[6] ],

    [ "called with a request outside the list, after the context",
        [ "$base_oid.5", $walk_base ], "NONE" ],
);


plan tests => 1 + 1 + 2 * @cases + 2 * (@context+1);

# load the module
use_ok("SNMP::ToolBox");

# check diagnostics
eval { find_next_oid() };
like($@, '/^error: first argument must be an arrayref/',
    "called with no arguments");

# check the different cases
for my $case (@cases) {
    my ($descr, $args, $rval) = @$case;
    my $next_oid = eval { find_next_oid(\@oid_list, @$args) };
    is($@, "", $descr);
    is($next_oid, $rval, " - find_next_oid(\@oid_list, @$args)");
}

# walk the MIB
my %next_of;
@next_of{$walk_base, @context} = (@context, "NONE");

my $curr_oid = $walk_base;

while ($curr_oid ne "NONE") {
    my $next_oid = eval { find_next_oid(\@oid_list, $curr_oid, $walk_base) };
    is($@, "", "walking $curr_oid -> $next_oid");
    is($next_oid, $next_of{$curr_oid},
        " - find_next_oid(\@oid_list, '$curr_oid', '$walk_base')");
    $curr_oid = $next_oid;
}
Something went wrong with that request. Please try again.