github.com/go-graphite/carbonapi@v0.17.0/expr/functions/removeBetweenPercentile/function_test.go (about) 1 package removeBetweenPercentile 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 TestFunction(t *testing.T) { 25 now32 := int64(time.Now().Unix()) 26 27 tests := []th.EvalTestItem{ 28 { 29 `removeBetweenPercentile(metric[1234], 30)`, 30 map[parser.MetricRequest][]*types.MetricData{ 31 {Metric: "metric[1234]", From: 0, Until: 1}: { 32 types.MakeMetricData("metric1", []float64{7, 7, 7, 7, 7, 7}, 1, now32), 33 types.MakeMetricData("metric2", []float64{5, 5, 5, 5, 5, 5}, 1, now32), 34 types.MakeMetricData("metric3", []float64{10, 10, 10, 10, 10, 10}, 1, now32), 35 types.MakeMetricData("metric4", []float64{1, 1, 1, 1, 1, 1}, 1, now32), 36 }, 37 }, 38 []*types.MetricData{ 39 types.MakeMetricData("removeBetweenPercentile(metric2, 30)", []float64{5, 5, 5, 5, 5, 5}, 1, now32), 40 types.MakeMetricData("removeBetweenPercentile(metric3, 30)", []float64{10, 10, 10, 10, 10, 10}, 1, now32), 41 types.MakeMetricData("removeBetweenPercentile(metric4, 30)", []float64{1, 1, 1, 1, 1, 1}, 1, now32), 42 }, 43 }, 44 } 45 46 for _, tt := range tests { 47 testName := tt.Target 48 t.Run(testName, func(t *testing.T) { 49 eval := th.EvaluatorFromFunc(md[0].F) 50 th.TestEvalExpr(t, eval, &tt) 51 }) 52 } 53 54 }