github.com/go-graphite/carbonapi@v0.17.0/expr/functions/join/function_test.go (about) 1 package join 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 TestFunction(t *testing.T) { 26 now32 := int64(time.Now().Unix()) 27 28 tests := []th.EvalTestItem{ 29 { 30 "join(metric1, metric2)", 31 map[parser.MetricRequest][]*types.MetricData{ 32 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32)}, 33 {Metric: "metric2", From: 0, Until: 1}: {types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32)}, 34 }, 35 []*types.MetricData{}, 36 }, 37 { 38 "join(metric1, metric2, \"OR\")", 39 map[parser.MetricRequest][]*types.MetricData{ 40 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32)}, 41 {Metric: "metric2", From: 0, Until: 1}: {types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32)}, 42 }, 43 []*types.MetricData{ 44 types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32), 45 types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32), 46 }, 47 }, 48 { 49 "join(metric1, metric2, \"XOR\")", 50 map[parser.MetricRequest][]*types.MetricData{ 51 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32)}, 52 {Metric: "metric2", From: 0, Until: 1}: {types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32)}, 53 }, 54 []*types.MetricData{ 55 types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32), 56 types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32), 57 }, 58 }, 59 { 60 "join(metric1, metric2, \"SUB\")", 61 map[parser.MetricRequest][]*types.MetricData{ 62 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32)}, 63 {Metric: "metric2", From: 0, Until: 1}: {types.MakeMetricData("metric2", []float64{1, 2, 3, -3, 4, 5}, 1, now32)}, 64 }, 65 []*types.MetricData{ 66 types.MakeMetricData("metric1", []float64{math.NaN(), -1, math.NaN(), -3, 4, 5}, 1, now32), 67 }, 68 }, 69 } 70 71 for _, tt := range tests { 72 testName := tt.Target 73 t.Run(testName, func(t *testing.T) { 74 eval := th.EvaluatorFromFunc(md[0].F) 75 th.TestEvalExpr(t, eval, &tt) 76 }) 77 } 78 79 }