github.com/go-graphite/carbonapi@v0.17.0/expr/functions/constantLine/function_test.go (about) 1 package constantLine 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 TestConstantLine(t *testing.T) { 24 tests := []th.EvalTestItem{ 25 { 26 "constantLine(42.42)", 27 map[parser.MetricRequest][]*types.MetricData{}, 28 []*types.MetricData{types.MakeMetricData("42.42", 29 []float64{42.42, 42.42}, 1, 0)}, 30 }, 31 { 32 "constantLine('42.42')", // Verify string input can be parsed into int or float 33 map[parser.MetricRequest][]*types.MetricData{}, 34 []*types.MetricData{types.MakeMetricData("42.42", 35 []float64{42.42, 42.42}, 1, 0)}, 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 }