github.com/go-graphite/carbonapi@v0.17.0/expr/functions/absolute/function_test.go (about) 1 package absolute 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 TestAbsolute(t *testing.T) { 25 now32 := int64(time.Now().Unix()) 26 27 tests := []th.EvalTestItem{ 28 { 29 "absolute(metric1)", 30 map[parser.MetricRequest][]*types.MetricData{ 31 {"metric1", "", 0, 1}: {types.MakeMetricData("metric1", []float64{0, -1, 2, -3, 4, 5}, 1, now32)}, 32 }, 33 []*types.MetricData{types.MakeMetricData("absolute(metric1)", 34 []float64{0, 1, 2, 3, 4, 5}, 1, now32).SetTag("absolute", "1").SetNameTag("absolute(metric1)")}, 35 }, 36 } 37 38 for _, tt := range tests { 39 testName := tt.Target 40 t.Run(testName, func(t *testing.T) { 41 eval := th.EvaluatorFromFunc(md[0].F) 42 th.TestEvalExpr(t, eval, &tt) 43 }) 44 } 45 }