File: test_mib.rb

package info (click to toggle)
libsnmp-ruby 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 1,420 kB
  • ctags: 581
  • sloc: ruby: 3,817; makefile: 41
file content (81 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download
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
require 'snmp/mib'
require 'test/unit'

module SNMP

class TestMib < Test::Unit::TestCase

    def setup
        @mib = MIB.new
        @mib.load_module("SNMPv2-MIB")
        @mib.load_module("IF-MIB")
    end
    
    def test_name_to_oid
        oid = @mib.oid("1.2.3.4")
        assert_equal("1.2.3.4", oid.to_s)
        
        oid = @mib.oid("ifTable")
        assert_equal("1.3.6.1.2.1.2.2", oid.to_s)

        oid = @mib.oid("sysDescr.0")
        assert_equal("1.3.6.1.2.1.1.1.0", oid.to_s)

        oid = @mib.oid("ifTable.1.23")
        assert_equal("1.3.6.1.2.1.2.2.1.23", oid.to_s)
        
        oid = @mib.oid("IF-MIB::ifTable.1.23")
        assert_equal("1.3.6.1.2.1.2.2.1.23", oid.to_s)
        
        assert_raise(MIB::ModuleNotLoadedError) {
            @mib.oid("IFMIB::ifTable.1.23")
        }
        
        assert_raise(ArgumentError) {
            @mib.oid("IF-MIB::")
        } 
        
        assert_raise(ArgumentError) {
           MIB.new.oid("sysDescr.0")
        }
        
        assert_equal("1.2.3.4", MIB.new.oid("1.2.3.4").to_s)
    end
    
    def test_varbind_list
        vb_list = @mib.varbind_list("1.2.3.4")
        assert_equal(1, vb_list.length)
        assert_equal("1.2.3.4", vb_list.first.name.to_s)

        vb_list = @mib.varbind_list(["1.2.3.4"])
        assert_equal(1, vb_list.length)
        assert_equal("1.2.3.4", vb_list.first.name.to_s)

        vb_list = @mib.varbind_list(["IF-MIB::ifTable.1.23", "1.2.3.4"])
        assert_equal(2, vb_list.length)
        assert_equal("1.3.6.1.2.1.2.2.1.23", vb_list.first.name.to_s)
    end
    
    def test_varbind
        vb = @mib.varbind("1.2.3.4", Null)
        assert_equal("1.2.3.4", vb.name.to_s)
        assert_equal(Null, vb.value)
        
        vb = @mib.varbind("IF-MIB::ifTable.3.45", Integer.new(2))
        assert_equal("1.3.6.1.2.1.2.2.3.45", vb.name.to_s)
        assert_equal(2, vb.value)
    end
    
    def test_list
        list = MIB.list_imported(/SNMPv2/)
        assert_equal(4, list.length)
    end
    
    # def test_import
    #     module_name = MIB.import_module('SNMPv2-MIB')
    #     assert_equal('SNMPv2-MIB', module_name)
    # end
    
end

end