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:
George Robinson
2021-07-15 13:10:56 +01:00
committed by GitHub
parent 421f5040ec
commit 456dac1303
9 changed files with 207 additions and 16 deletions

View 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())
})
}
}