mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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 }}"
This commit is contained in:
34
pkg/services/ngalert/state/cache_test.go
Normal file
34
pkg/services/ngalert/state/cache_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user