github.com/go-graphite/carbonapi@v0.17.0/expr/functions/heatMap/function_test.go (about) 1 package heatMap 2 3 import ( 4 "math" 5 "testing" 6 "time" 7 8 "github.com/go-graphite/carbonapi/expr/interfaces" 9 "github.com/go-graphite/carbonapi/expr/metadata" 10 "github.com/go-graphite/carbonapi/expr/types" 11 "github.com/go-graphite/carbonapi/pkg/parser" 12 th "github.com/go-graphite/carbonapi/tests" 13 ) 14 15 var ( 16 md []interfaces.FunctionMetadata = New("") 17 ) 18 19 func init() { 20 for _, m := range md { 21 metadata.RegisterFunction(m.Name, m.F) 22 } 23 } 24 25 func TestHeatMap(t *testing.T) { 26 now32 := int64(time.Now().Unix()) 27 28 tests := []th.EvalTestItem{ 29 { 30 "heatMap(a.*)", 31 map[parser.MetricRequest][]*types.MetricData{ 32 {Metric: "a.*", From: 0, Until: 1}: { 33 types.MakeMetricData("a.a1", []float64{1, 2, 3, 4, 5, 6}, 1, now32), 34 types.MakeMetricData("a.a2", []float64{2, math.NaN(), 20, 8, 10, 7}, 1, now32), 35 types.MakeMetricData("a.a3", []float64{10, math.NaN(), 3, 17, 10, 90}, 1, now32), 36 }, 37 }, 38 []*types.MetricData{ 39 types.MakeMetricData("heatMap(a.a2,a.a1)", []float64{1.0, math.NaN(), 17.0, 4.0, 5.0, 1.0}, 1, now32), 40 types.MakeMetricData("heatMap(a.a3,a.a2)", []float64{8.0, math.NaN(), -17.0, 9.0, 0.0, 83.0}, 1, now32), 41 }, 42 }, 43 } 44 45 for _, tt := range tests { 46 testName := tt.Target 47 t.Run(testName, func(t *testing.T) { 48 eval := th.EvaluatorFromFunc(md[0].F) 49 th.TestEvalExpr(t, eval, &tt) 50 }) 51 } 52 }