feat(pkg): thresholds on perfdata can be cleared using Set...(nil)
This commit is contained in:
parent
14c7a0e5e8
commit
1a35167eab
2 changed files with 44 additions and 4 deletions
|
@ -35,14 +35,22 @@ func New(label string, units UnitOfMeasurement, value string) *PerfData {
|
|||
|
||||
// Set the warning range for the performance data record.
|
||||
func (d *PerfData) SetWarn(r *Range) {
|
||||
d.warn = *r
|
||||
d.bits |= PDatWarn
|
||||
if r == nil {
|
||||
d.bits &^= PDatWarn
|
||||
} else {
|
||||
d.warn = *r
|
||||
d.bits |= PDatWarn
|
||||
}
|
||||
}
|
||||
|
||||
// Set the critical range for the performance data record.
|
||||
func (d *PerfData) SetCrit(r *Range) {
|
||||
d.crit = *r
|
||||
d.bits |= PDatCrit
|
||||
if r == nil {
|
||||
d.bits &^= PDatCrit
|
||||
} else {
|
||||
d.crit = *r
|
||||
d.bits |= PDatCrit
|
||||
}
|
||||
}
|
||||
|
||||
// Set the performance data's minimal value.
|
||||
|
|
|
@ -50,6 +50,12 @@ func TestSetWarn(t *testing.T) {
|
|||
assert.Equal(t, rangeStr, data.warn.String())
|
||||
}
|
||||
|
||||
func TestSetWarnNil(t *testing.T) {
|
||||
data := PerfData{}
|
||||
data.SetWarn(nil)
|
||||
assert.Equal(t, perfDataBits(0), data.bits&PDatWarn)
|
||||
}
|
||||
|
||||
func TestSetWarnTwice(t *testing.T) {
|
||||
range1Value := Range{start: "A", end: "B"}
|
||||
range2Value := Range{start: "C", end: "D"}
|
||||
|
@ -64,6 +70,16 @@ func TestSetWarnTwice(t *testing.T) {
|
|||
assert.Equal(t, range2Str, data.warn.String())
|
||||
}
|
||||
|
||||
func TestSetWarnClear(t *testing.T) {
|
||||
range1Value := Range{start: "A", end: "B"}
|
||||
|
||||
data := PerfData{}
|
||||
data.SetWarn(&range1Value)
|
||||
data.SetWarn(nil)
|
||||
|
||||
assert.Equal(t, perfDataBits(0), data.bits&PDatWarn)
|
||||
}
|
||||
|
||||
func TestSetCrit(t *testing.T) {
|
||||
rangeValue := Range{start: "A", end: "B"}
|
||||
rangeStr := rangeValue.String()
|
||||
|
@ -75,6 +91,12 @@ func TestSetCrit(t *testing.T) {
|
|||
assert.Equal(t, rangeStr, data.crit.String())
|
||||
}
|
||||
|
||||
func TestSetCritNil(t *testing.T) {
|
||||
data := PerfData{}
|
||||
data.SetCrit(nil)
|
||||
assert.Equal(t, perfDataBits(0), data.bits&PDatCrit)
|
||||
}
|
||||
|
||||
func TestSetCritTwice(t *testing.T) {
|
||||
range1Value := Range{start: "A", end: "B"}
|
||||
range2Value := Range{start: "C", end: "D"}
|
||||
|
@ -89,6 +111,16 @@ func TestSetCritTwice(t *testing.T) {
|
|||
assert.Equal(t, range2Str, data.crit.String())
|
||||
}
|
||||
|
||||
func TestSetCritClear(t *testing.T) {
|
||||
range1Value := Range{start: "A", end: "B"}
|
||||
|
||||
data := PerfData{}
|
||||
data.SetCrit(&range1Value)
|
||||
data.SetCrit(nil)
|
||||
|
||||
assert.Equal(t, perfDataBits(0), data.bits&PDatCrit)
|
||||
}
|
||||
|
||||
func TestSetMin(t *testing.T) {
|
||||
const min = "100"
|
||||
|
||||
|
|
Loading…
Reference in a new issue