github.com/go-graphite/carbonapi@v0.17.0/expr/functions/unique/function_test.go (about) 1 package unique 2 3 import ( 4 "math" 5 "testing" 6 "time" 7 8 "github.com/go-graphite/carbonapi/expr/interfaces" 9 "github.com/go-graphite/carbonapi/expr/metadata" 10 "github.com/go-graphite/carbonapi/expr/types" 11 "github.com/go-graphite/carbonapi/pkg/parser" 12 th "github.com/go-graphite/carbonapi/tests" 13 ) 14 15 var ( 16 md []interfaces.FunctionMetadata = New("") 17 ) 18 19 func init() { 20 for _, m := range md { 21 metadata.RegisterFunction(m.Name, m.F) 22 } 23 } 24 25 func TestUnique(t *testing.T) { 26 now32 := int64(time.Now().Unix()) 27 28 tests := []th.EvalTestItem{ 29 { 30 `unique(metric[1234])`, 31 map[parser.MetricRequest][]*types.MetricData{ 32 {Metric: "metric[1234]", From: 0, Until: 1}: { 33 types.MakeMetricData("metric1.foo.bar.baz", []float64{1, math.NaN(), 2, 3, 4, 5}, 1, now32), 34 types.MakeMetricData("metric2.foo.bar.baz", []float64{2, math.NaN(), 3, math.NaN(), 5, 6}, 1, now32), 35 types.MakeMetricData("metric3.foo.bar.baz", []float64{3, math.NaN(), 4, 5, 6, math.NaN()}, 1, now32), 36 types.MakeMetricData("metric1.foo.bar.baz", []float64{4, math.NaN(), 5, 6, 7, math.NaN()}, 1, now32), 37 }, 38 }, 39 []*types.MetricData{ 40 types.MakeMetricData("metric1.foo.bar.baz", []float64{1, math.NaN(), 2, 3, 4, 5}, 1, now32), 41 types.MakeMetricData("metric2.foo.bar.baz", []float64{2, math.NaN(), 3, math.NaN(), 5, 6}, 1, now32), 42 types.MakeMetricData("metric3.foo.bar.baz", []float64{3, math.NaN(), 4, 5, 6, math.NaN()}, 1, now32), 43 }, 44 }, 45 } 46 47 for _, tt := range tests { 48 testName := tt.Target 49 t.Run(testName, func(t *testing.T) { 50 eval := th.EvaluatorFromFunc(md[0].F) 51 th.TestEvalExpr(t, eval, &tt) 52 }) 53 } 54 }