Files
grafana/pkg/services/ngalert/state/cache_test.go
T
George Robinson 456dac1303 Expand the value of math and reduce expressions in annotations and labels (#36611)
* Expand the value of math and reduce expressions in annotations and labels

This commit makes it possible to use the values of reduce and math
expressions in annotations and labels via their RefIDs. It uses the
Stringer interface to ensure that "{{ $values.A }}" still prints the
value in decimal format while also making the labels for each RefID
available with "{{ $values.A.Labels }}" and the float64 value with
"{{ $values.A.Value }}"
2021-07-15 13:10:56 +01:00

35 lines
753 B
Go

package state
import (
"testing"
"github.com/stretchr/testify/assert"
ptr "github.com/xorcare/pointer"
)
func TestTemplateCaptureValueStringer(t *testing.T) {
cases := []struct {
name string
value templateCaptureValue
expected string
}{{
name: "nil value returns null",
value: templateCaptureValue{Value: nil},
expected: "null",
}, {
name: "1.0 is returned as integer value",
value: templateCaptureValue{Value: ptr.Float64(1.0)},
expected: "1",
}, {
name: "1.1 is returned as decimal value",
value: templateCaptureValue{Value: ptr.Float64(1.1)},
expected: "1.1",
}}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
assert.Equal(t, c.expected, c.value.String())
})
}
}