-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoid_test.go
39 lines (31 loc) · 940 Bytes
/
oid_test.go
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
package snmp
import (
"bytes"
"testing"
)
func TestEncodeAndParseOID(t *testing.T) {
oid := ObjectIdentifier{1, 3, 6, 1, 4, 1, 2636, 3, 2, 3, 1, 20}
b, err := oid.Encode()
if err != nil {
t.Fatal(err)
}
if expected := []byte{
0x6, 0x0c,
0x2b, 0x06, 0x01, 0x04,
0x01, 0x94, 0x4c, 0x03,
0x02, 0x03, 0x01, 0x14,
}; !bytes.Equal(expected, b) {
t.Errorf("encoded ObjectIdentifer incorrect. Expected %v, got %v", expected, b)
}
parsed := MustParseOID(oid.String())
if oid.String() != parsed.String() {
t.Errorf("expected parsed ObjectIdentifer %v, got %v", oid, parsed)
}
}
func TestOIDLargeNumbers(t *testing.T) {
oid := MustParseOID(".1.3.6.1.2.1.7.7.1.8.1.4.0.0.0.0.68.1.4.0.0.0.0.0.2464081")
if oid.String() != ".1.3.6.1.2.1.7.7.1.8.1.4.0.0.0.0.68.1.4.0.0.0.0.0.2464081" {
t.Errorf("expected ObjectIdentifer %s, got %s",
".1.3.6.1.2.1.7.7.1.8.1.4.0.0.0.0.68.1.4.0.0.0.0.0.2464081", oid.String())
}
}