github.com/go-graphite/carbonapi@v0.17.0/expr/functions/mostDeviant/function_test.go (about) 1 package mostDeviant 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/go-graphite/carbonapi/expr/interfaces" 8 "github.com/go-graphite/carbonapi/expr/metadata" 9 "github.com/go-graphite/carbonapi/expr/types" 10 "github.com/go-graphite/carbonapi/pkg/parser" 11 th "github.com/go-graphite/carbonapi/tests" 12 ) 13 14 var ( 15 md []interfaces.FunctionMetadata = New("") 16 ) 17 18 func init() { 19 for _, m := range md { 20 metadata.RegisterFunction(m.Name, m.F) 21 } 22 } 23 24 func TestFunctionMultiReturn(t *testing.T) { 25 now32 := int64(time.Now().Unix()) 26 27 tests := []th.MultiReturnEvalTestItem{ 28 { 29 "mostDeviant(2,metric*)", 30 map[parser.MetricRequest][]*types.MetricData{ 31 {Metric: "metric*", From: 0, Until: 1}: { 32 types.MakeMetricData("metricA", []float64{0, 0, 0, 0, 0, 0}, 1, now32), 33 types.MakeMetricData("metricB", []float64{3, 4, 5, 6, 7, 8}, 1, now32), 34 types.MakeMetricData("metricC", []float64{4, 4, 5, 5, 6, 6}, 1, now32), 35 types.MakeMetricData("metricD", []float64{4, 4, 5, 5, 6, 6}, 1, now32), 36 types.MakeMetricData("metricE", []float64{4, 7, 7, 7, 7, 1}, 1, now32), 37 }, 38 }, 39 "mostDeviant", 40 map[string][]*types.MetricData{ 41 "metricB": {types.MakeMetricData("metricB", []float64{3, 4, 5, 6, 7, 8}, 1, now32)}, 42 "metricE": {types.MakeMetricData("metricE", []float64{4, 7, 7, 7, 7, 1}, 1, now32)}, 43 }, 44 }, 45 { 46 "mostDeviant(metric*,2)", 47 map[parser.MetricRequest][]*types.MetricData{ 48 {Metric: "metric*", From: 0, Until: 1}: { 49 types.MakeMetricData("metricA", []float64{0, 0, 0, 0, 0, 0}, 1, now32), 50 types.MakeMetricData("metricB", []float64{3, 4, 5, 6, 7, 8}, 1, now32), 51 types.MakeMetricData("metricC", []float64{4, 4, 5, 5, 6, 6}, 1, now32), 52 types.MakeMetricData("metricD", []float64{4, 4, 5, 5, 6, 6}, 1, now32), 53 types.MakeMetricData("metricE", []float64{4, 7, 7, 7, 7, 1}, 1, now32), 54 }, 55 }, 56 "mostDeviant", 57 map[string][]*types.MetricData{ 58 "metricB": {types.MakeMetricData("metricB", []float64{3, 4, 5, 6, 7, 8}, 1, now32)}, 59 "metricE": {types.MakeMetricData("metricE", []float64{4, 7, 7, 7, 7, 1}, 1, now32)}, 60 }, 61 }, 62 } 63 64 for _, tt := range tests { 65 testName := tt.Target 66 t.Run(testName, func(t *testing.T) { 67 eval := th.EvaluatorFromFunc(md[0].F) 68 th.TestMultiReturnEvalExpr(t, eval, &tt) 69 }) 70 } 71 72 }