github.com/go-graphite/carbonapi@v0.17.0/expr/functions/integralByInterval/function_test.go (about) 1 package integralByInterval 2 3 import ( 4 "testing" 5 6 "github.com/go-graphite/carbonapi/expr/interfaces" 7 "github.com/go-graphite/carbonapi/expr/metadata" 8 "github.com/go-graphite/carbonapi/expr/types" 9 "github.com/go-graphite/carbonapi/pkg/parser" 10 th "github.com/go-graphite/carbonapi/tests" 11 ) 12 13 var ( 14 md []interfaces.FunctionMetadata = New("") 15 ) 16 17 func init() { 18 for _, m := range md { 19 metadata.RegisterFunction(m.Name, m.F) 20 } 21 } 22 23 func TestFunction(t *testing.T) { 24 tests := []th.EvalTestItem{ 25 { 26 "integralByInterval(10s,'10s')", 27 map[parser.MetricRequest][]*types.MetricData{ 28 {Metric: "10s", From: 0, Until: 1}: { 29 types.MakeMetricData("10s", []float64{1, 0, 2, 3, 4, 5, 0, 7, 8, 9, 10}, 2, 0), 30 }, 31 }, 32 []*types.MetricData{types.MakeMetricData( 33 "integralByInterval(10s,'10s')", 34 []float64{1, 1, 3, 6, 10, 5, 5, 12, 20, 29, 10}, 2, 0).SetTag("integralByInterval", "10s"), 35 }, 36 }, 37 } 38 39 for _, tt := range tests { 40 testName := tt.Target 41 t.Run(testName, func(t *testing.T) { 42 eval := th.EvaluatorFromFunc(md[0].F) 43 th.TestEvalExpr(t, eval, &tt) 44 }) 45 } 46 47 }