github.com/go-graphite/carbonapi@v0.17.0/expr/functions/toUpperCase/function_test.go (about)

     1  package toUpperCase
     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 TestToUpperCaseFunction(t *testing.T) {
    26  	now32 := time.Now().Unix()
    27  
    28  	tests := []th.EvalTestItem{
    29  		{
    30  			"upper(metric.test.foo)",
    31  			map[parser.MetricRequest][]*types.MetricData{
    32  				{Metric: "metric.test.foo", From: 0, Until: 1}: {types.MakeMetricData("metric.test.foo", []float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    33  			},
    34  			[]*types.MetricData{types.MakeMetricData("METRIC.TEST.FOO",
    35  				[]float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    36  		},
    37  		{
    38  			"upper(metric.test.foo,7)",
    39  			map[parser.MetricRequest][]*types.MetricData{
    40  				{Metric: "metric.test.foo", From: 0, Until: 1}: {types.MakeMetricData("metric.test.foo", []float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    41  			},
    42  			[]*types.MetricData{types.MakeMetricData("metric.Test.foo",
    43  				[]float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    44  		},
    45  		{
    46  			"upper(metric.test.foo,-3)",
    47  			map[parser.MetricRequest][]*types.MetricData{
    48  				{Metric: "metric.test.foo", From: 0, Until: 1}: {types.MakeMetricData("metric.test.foo", []float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    49  			},
    50  			[]*types.MetricData{types.MakeMetricData("metric.test.Foo",
    51  				[]float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    52  		},
    53  		{
    54  			"upper(metric.test.foo,0,7,12)",
    55  			map[parser.MetricRequest][]*types.MetricData{
    56  				{Metric: "metric.test.foo", From: 0, Until: 1}: {types.MakeMetricData("metric.test.foo", []float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    57  			},
    58  			[]*types.MetricData{types.MakeMetricData("Metric.Test.Foo",
    59  				[]float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    60  		},
    61  		{
    62  			"toUpperCase(metric.test.foo)",
    63  			map[parser.MetricRequest][]*types.MetricData{
    64  				{Metric: "metric.test.foo", From: 0, Until: 1}: {types.MakeMetricData("metric.test.foo", []float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    65  			},
    66  			[]*types.MetricData{types.MakeMetricData("METRIC.TEST.FOO",
    67  				[]float64{1, 2, 0, 7, 8, 20, 30, math.NaN()}, 1, now32)},
    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  }