forked from gosnmp/gosnmp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc_test.go
96 lines (82 loc) · 2.25 KB
/
misc_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2012-2014 The GoSNMP Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
package gosnmp
import (
"fmt"
"reflect"
"testing"
)
var _ = fmt.Sprintf("dummy") // dummy
// Tests in alphabetical order of function being tested
// -----------------------------------------------------------------------------
var testsMarshalLength = []struct {
length int
expected []byte
}{
{1, []byte{0x01}},
{129, []byte{0x81, 0x81}},
{256, []byte{0x82, 0x01, 0x00}},
{272, []byte{0x82, 0x01, 0x10}},
{435, []byte{0x82, 0x01, 0xb3}},
}
func TestMarshalLength(t *testing.T) {
for i, test := range testsMarshalLength {
testBytes, err := marshalLength(test.length)
if err != nil {
t.Errorf("%d: length %d got err %v", i, test.length, err)
}
if !reflect.DeepEqual(testBytes, test.expected) {
t.Errorf("%d: length %d got |%x| expected |%x|",
i, test.length, testBytes, test.expected)
}
}
}
// -----------------------------------------------------------------------------
var testsPartition = []struct {
currentPosition int
partitionSize int
sliceLength int
ok bool
}{
{-1, 3, 8, false}, // test out of range
{8, 3, 8, false}, // test out of range
{0, 3, 8, false}, // test 0-7/3 per doco
{1, 3, 8, false},
{2, 3, 8, true},
{3, 3, 8, false},
{4, 3, 8, false},
{5, 3, 8, true},
{6, 3, 8, false},
{7, 3, 8, true},
{-1, 1, 3, false}, // partition size of one
{0, 1, 3, true},
{1, 1, 3, true},
{2, 1, 3, true},
{3, 1, 3, false},
}
func TestPartition(t *testing.T) {
for i, test := range testsPartition {
ok := Partition(test.currentPosition, test.partitionSize, test.sliceLength)
if ok != test.ok {
t.Errorf("#%d: Bad result: %v (expected %v)", i, ok, test.ok)
}
}
}
// ---------------------------------------------------------------------
var testsSnmpVersionString = []struct {
in SnmpVersion
out string
}{
{Version1, "1"},
{Version2c, "2c"},
}
func TestSnmpVersionString(t *testing.T) {
for i, test := range testsSnmpVersionString {
result := test.in.String()
if result != test.out {
t.Errorf("#%d, got %v expected %v", i, result, test.out)
}
}
}
// ---------------------------------------------------------------------