-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoid_sorter_test.go
80 lines (70 loc) · 2.34 KB
/
oid_sorter_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
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
package main
import (
"reflect"
"sort"
"testing"
"github.com/posteo/go-agentx/value"
)
func TestOIDSort(t *testing.T) {
in := []value.OID{
value.MustParseOID("1.3.6"),
value.MustParseOID("1.3.6.3"),
value.MustParseOID("1.3.6.3.1"),
value.MustParseOID("1.3.6.3"),
value.MustParseOID("1.3.6"),
value.MustParseOID("1.3.6.1.3"),
value.MustParseOID("1.3.6.10.2"),
value.MustParseOID("1.3.6.100.1"),
value.MustParseOID("1.3.6.10.1"),
value.MustParseOID("1.3.6.1.2"),
value.MustParseOID("1.3.6.2.2"),
value.MustParseOID("1.3.6.1.3"),
value.MustParseOID("1.3.6.2.1"),
}
out := []value.OID{
value.MustParseOID("1.3.6"),
value.MustParseOID("1.3.6"),
value.MustParseOID("1.3.6.1.2"),
value.MustParseOID("1.3.6.1.3"),
value.MustParseOID("1.3.6.1.3"),
value.MustParseOID("1.3.6.2.1"),
value.MustParseOID("1.3.6.2.2"),
value.MustParseOID("1.3.6.3"),
value.MustParseOID("1.3.6.3"),
value.MustParseOID("1.3.6.3.1"),
value.MustParseOID("1.3.6.10.1"),
value.MustParseOID("1.3.6.10.2"),
value.MustParseOID("1.3.6.100.1"),
}
sort.Sort(OIDSorter(in))
if !reflect.DeepEqual(in, out) {
t.Errorf("Error sorting oids. Expected %+v. Got %+v", out, in)
}
}
func TestOIDComparison(t *testing.T) {
test_data := []struct {
left string
right string
less_than bool
}{
{"1.3.6.1", "1.3.6.2", true},
{"1.3.6.1", "1.3.6.10", true},
{"1.3.6.1.1", "1.3.6.10.1", true},
{"1.3.6.1.1", "1.3.6", false},
{"1.30.6.1.1", "1.300.6", true},
}
for _, test_row := range test_data {
if OIDLessThan(value.MustParseOID(test_row.left), value.MustParseOID(test_row.right)) != test_row.less_than {
t.Errorf("%v < %v was expected to be %v", test_row.left, test_row.right, test_row.less_than)
}
if OIDLessThan(value.MustParseOID(test_row.right), value.MustParseOID(test_row.left)) == test_row.less_than {
t.Errorf("%v < %v was expected to be %v", test_row.right, test_row.left, !test_row.less_than)
}
if OIDGreaterThan(value.MustParseOID(test_row.left), value.MustParseOID(test_row.right)) == test_row.less_than {
t.Errorf("%v > %v was expected to be %v", test_row.left, test_row.right, !test_row.less_than)
}
if OIDGreaterThan(value.MustParseOID(test_row.right), value.MustParseOID(test_row.left)) != test_row.less_than {
t.Errorf("%v > %v was expected to be %v", test_row.right, test_row.left, test_row.less_than)
}
}
}