@@ -16,9 +16,8 @@ func TestSingleNTPQ(t *testing.T) {
|
||||
ret: []byte(singleNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -46,9 +45,8 @@ func TestBadIntNTPQ(t *testing.T) {
|
||||
ret: []byte(badIntParseNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
@@ -75,9 +73,8 @@ func TestBadFloatNTPQ(t *testing.T) {
|
||||
ret: []byte(badFloatParseNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
@@ -104,9 +101,8 @@ func TestDaysNTPQ(t *testing.T) {
|
||||
ret: []byte(whenDaysNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -134,9 +130,8 @@ func TestHoursNTPQ(t *testing.T) {
|
||||
ret: []byte(whenHoursNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -164,9 +159,8 @@ func TestMinutesNTPQ(t *testing.T) {
|
||||
ret: []byte(whenMinutesNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -194,9 +188,8 @@ func TestBadWhenNTPQ(t *testing.T) {
|
||||
ret: []byte(whenBadNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
@@ -226,9 +219,8 @@ func TestParserNTPQ(t *testing.T) {
|
||||
err: nil,
|
||||
}
|
||||
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
@@ -289,9 +281,8 @@ func TestMultiNTPQ(t *testing.T) {
|
||||
ret: []byte(multiNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -330,14 +321,12 @@ func TestMultiNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadHeaderNTPQ(t *testing.T) {
|
||||
resetVars()
|
||||
tt := tester{
|
||||
ret: []byte(badHeaderNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -360,14 +349,12 @@ func TestBadHeaderNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMissingDelayColumnNTPQ(t *testing.T) {
|
||||
resetVars()
|
||||
tt := tester{
|
||||
ret: []byte(missingDelayNTPQ),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
@@ -393,9 +380,8 @@ func TestFailedNTPQ(t *testing.T) {
|
||||
ret: []byte(singleNTPQ),
|
||||
err: fmt.Errorf("Test failure"),
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
@@ -445,9 +431,8 @@ func TestNoRefID(t *testing.T) {
|
||||
ret: []byte(noRefID),
|
||||
err: nil,
|
||||
}
|
||||
n := &NTPQ{
|
||||
runQ: tt.runqTest,
|
||||
}
|
||||
n := newNTPQ()
|
||||
n.runQ = tt.runqTest
|
||||
|
||||
acc := testutil.Accumulator{
|
||||
TimeFunc: func() time.Time { return now },
|
||||
@@ -466,38 +451,6 @@ func (t *tester) runqTest() ([]byte, error) {
|
||||
return t.ret, t.err
|
||||
}
|
||||
|
||||
func resetVars() {
|
||||
// Mapping of ntpq header names to tag keys
|
||||
tagHeaders = map[string]string{
|
||||
"remote": "remote",
|
||||
"refid": "refid",
|
||||
"st": "stratum",
|
||||
"t": "type",
|
||||
}
|
||||
|
||||
// Mapping of the ntpq tag key to the index in the command output
|
||||
tagI = map[string]int{
|
||||
"remote": -1,
|
||||
"refid": -1,
|
||||
"stratum": -1,
|
||||
"type": -1,
|
||||
}
|
||||
|
||||
// Mapping of float metrics to their index in the command output
|
||||
floatI = map[string]int{
|
||||
"delay": -1,
|
||||
"offset": -1,
|
||||
"jitter": -1,
|
||||
}
|
||||
|
||||
// Mapping of int metrics to their index in the command output
|
||||
intI = map[string]int{
|
||||
"when": -1,
|
||||
"poll": -1,
|
||||
"reach": -1,
|
||||
}
|
||||
}
|
||||
|
||||
var singleNTPQ = ` remote refid st t when poll reach delay offset jitter
|
||||
==============================================================================
|
||||
*uschi5-ntp-002. 10.177.80.46 2 u 101 256 37 51.016 233.010 17.462
|
||||
|
||||
Reference in New Issue
Block a user