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

     1  package identity
     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 TestIdentityFunction(t *testing.T) {
    24  	var startTime int64 = 0
    25  
    26  	tests := []th.EvalTestItemWithRange{
    27  		{
    28  			Target: `identity("The.time.series")`,
    29  			M: map[parser.MetricRequest][]*types.MetricData{
    30  				{From: startTime, Until: startTime + 240}: {},
    31  			},
    32  			Want: []*types.MetricData{types.MakeMetricData("identity(The.time.series)",
    33  				[]float64{0, 60, 120, 180}, 60, startTime)},
    34  			From:  startTime,
    35  			Until: startTime + 240,
    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.TestEvalExprWithRange(t, eval, &tt)
    44  		})
    45  	}
    46  }