-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpoller_test.go
More file actions
97 lines (87 loc) · 2.08 KB
/
poller_test.go
File metadata and controls
97 lines (87 loc) · 2.08 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
89
90
91
92
93
94
95
96
97
// Copyright 2016 Paul Stuart. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
package snmputil
import (
"fmt"
"strings"
"testing"
"time"
)
const (
testOID = "ifEntry"
testFreq = 30
)
var (
testCrit = Criteria{
OID: testOID,
Tags: testTags,
Freq: testFreq,
Count: 1,
}
)
func walkTest(t *testing.T, p Profile, c Criteria) {
errFn := func(err error) {
if err != nil {
t.Error(err)
}
}
testSender := func(name string, tags map[string]string, value interface{}, ts TimeStamp) error {
t.Logf("Name:%s Value:%v Time:%s Tags:%v\n", name, value, ts.Start, tags)
return nil
}
if err := Poller(p, c, testSender, errFn, logger); err != nil {
t.Error(err)
}
}
func TestSNMPv2(t *testing.T) {
walkTest(t, profileV2, testCrit)
}
func TestSNMPv3(t *testing.T) {
walkTest(t, profileV3, testCrit)
}
func TestFilters(t *testing.T) {
errFn := func(err error) {
if err != nil {
t.Error(err)
}
}
testSender := func(name string, tags map[string]string, value interface{}, ts TimeStamp) error {
t.Logf("Name:%s Value:%v Time:%s Tags:%v\n", name, value, ts.Start, tags)
if strings.HasSuffix(name, "Time") {
return fmt.Errorf("did not expect name with Time suffix: %s", name)
}
return nil
}
crit := Criteria{
OID: "system",
Tags: testTags,
Count: 1,
}
regexps := []string{".*Time"}
testSender, _ = RegexpSender(testSender, regexps, false)
if err := Poller(profileV2, crit, testSender, errFn, nil); err != nil {
t.Error(err)
}
time.Sleep(10 * time.Second)
}
func TestSample(t *testing.T) {
crit := Criteria{
OID: "system",
Tags: testTags,
Regexps: []string{".*Time"},
Count: 1,
}
sender := func(name string, tags map[string]string, value interface{}, ts TimeStamp) error {
t.Logf("Host:%s Name:%s Value:%v Tags:%v\n", tags["host"], name, value, tags)
return nil
}
if err := Sampler(profileV3, crit, sender); err != nil {
t.Error(err)
}
}
func TestClose(t *testing.T) {
// give it a chance to respond with values
time.Sleep(5 * time.Second)
Quit()
}