Add fields value test methods
This commit is contained in:
parent
55c598f9ff
commit
b2e22cbc59
|
@ -106,15 +106,20 @@ func (a *Accumulator) Get(measurement string) (*Point, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckValue calls CheckFieldsValue passing a single-value map as fields
|
||||||
|
func (a *Accumulator) CheckValue(measurement string, val interface{}) bool {
|
||||||
|
return a.CheckFieldsValue(measurement, map[string]interface{}{"value": val})
|
||||||
|
}
|
||||||
|
|
||||||
// CheckValue checks that the accumulators point for the given measurement
|
// CheckValue checks that the accumulators point for the given measurement
|
||||||
// is the same as the given value.
|
// is the same as the given value.
|
||||||
func (a *Accumulator) CheckValue(measurement string, val interface{}) bool {
|
func (a *Accumulator) CheckFieldsValue(measurement string, fields map[string]interface{}) bool {
|
||||||
for _, p := range a.Points {
|
for _, p := range a.Points {
|
||||||
if p.Measurement == measurement {
|
if p.Measurement == measurement {
|
||||||
return p.Values["value"] == val
|
return reflect.DeepEqual(fields, p.Values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("CheckValue failed, measurement %s, value %s", measurement, val)
|
fmt.Printf("CheckFieldsValue failed, measurement %s, fields %s", measurement, fields)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,12 +132,35 @@ func (a *Accumulator) CheckTaggedValue(
|
||||||
return a.ValidateTaggedValue(measurement, val, tags) == nil
|
return a.ValidateTaggedValue(measurement, val, tags) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateTaggedValue validates that the given measurement and value exist
|
// ValidateTaggedValue calls ValidateTaggedFieldsValue passing a single-value map as fields
|
||||||
// in the accumulator and with the given tags.
|
|
||||||
func (a *Accumulator) ValidateTaggedValue(
|
func (a *Accumulator) ValidateTaggedValue(
|
||||||
measurement string,
|
measurement string,
|
||||||
val interface{},
|
val interface{},
|
||||||
tags map[string]string,
|
tags map[string]string,
|
||||||
|
) error {
|
||||||
|
return a.ValidateTaggedFieldsValue(measurement, map[string]interface{}{"value": val}, tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateValue calls ValidateTaggedValue
|
||||||
|
func (a *Accumulator) ValidateValue(measurement string, val interface{}) error {
|
||||||
|
return a.ValidateTaggedValue(measurement, val, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckTaggedFieldsValue calls ValidateTaggedFieldsValue
|
||||||
|
func (a *Accumulator) CheckTaggedFieldsValue(
|
||||||
|
measurement string,
|
||||||
|
fields map[string]interface{},
|
||||||
|
tags map[string]string,
|
||||||
|
) bool {
|
||||||
|
return a.ValidateTaggedFieldsValue(measurement, fields, tags) == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateTaggedValue validates that the given measurement and value exist
|
||||||
|
// in the accumulator and with the given tags.
|
||||||
|
func (a *Accumulator) ValidateTaggedFieldsValue(
|
||||||
|
measurement string,
|
||||||
|
fields map[string]interface{},
|
||||||
|
tags map[string]string,
|
||||||
) error {
|
) error {
|
||||||
if tags == nil {
|
if tags == nil {
|
||||||
tags = map[string]string{}
|
tags = map[string]string{}
|
||||||
|
@ -143,9 +171,8 @@ func (a *Accumulator) ValidateTaggedValue(
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Measurement == measurement {
|
if p.Measurement == measurement {
|
||||||
if p.Values["value"] != val {
|
if !reflect.DeepEqual(fields, p.Values) {
|
||||||
return fmt.Errorf("%v (%T) != %v (%T)",
|
return fmt.Errorf("%v != %v ", fields, p.Values)
|
||||||
p.Values["value"], p.Values["value"], val, val)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -154,9 +181,12 @@ func (a *Accumulator) ValidateTaggedValue(
|
||||||
return fmt.Errorf("unknown measurement %s with tags %v", measurement, tags)
|
return fmt.Errorf("unknown measurement %s with tags %v", measurement, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateValue calls ValidateTaggedValue
|
// ValidateFieldsValue calls ValidateTaggedFieldsValue
|
||||||
func (a *Accumulator) ValidateValue(measurement string, val interface{}) error {
|
func (a *Accumulator) ValidateFieldsValue(
|
||||||
return a.ValidateTaggedValue(measurement, val, nil)
|
measurement string,
|
||||||
|
fields map[string]interface{},
|
||||||
|
) error {
|
||||||
|
return a.ValidateTaggedValue(measurement, fields, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Accumulator) ValidateTaggedFields(
|
func (a *Accumulator) ValidateTaggedFields(
|
||||||
|
|
Loading…
Reference in New Issue