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

     1  package exclude
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/go-graphite/carbonapi/expr/interfaces"
     8  	"github.com/go-graphite/carbonapi/expr/metadata"
     9  	"github.com/go-graphite/carbonapi/expr/types"
    10  	"github.com/go-graphite/carbonapi/pkg/parser"
    11  	th "github.com/go-graphite/carbonapi/tests"
    12  )
    13  
    14  var (
    15  	md []interfaces.FunctionMetadata = New("")
    16  )
    17  
    18  func init() {
    19  	for _, m := range md {
    20  		metadata.RegisterFunction(m.Name, m.F)
    21  	}
    22  }
    23  
    24  func TestExclude(t *testing.T) {
    25  	now32 := int64(time.Now().Unix())
    26  
    27  	tests := []th.EvalTestItem{
    28  		{
    29  			"exclude(metric1,\"(Foo|Baz)\")",
    30  			map[parser.MetricRequest][]*types.MetricData{
    31  				{Metric: "metric1", From: 0, Until: 1}: {
    32  					types.MakeMetricData("metricFoo", []float64{1, 1, 1, 1, 1}, 1, now32),
    33  					types.MakeMetricData("metricBar", []float64{2, 2, 2, 2, 2}, 1, now32),
    34  					types.MakeMetricData("metricBaz", []float64{3, 3, 3, 3, 3}, 1, now32),
    35  				},
    36  			},
    37  			[]*types.MetricData{types.MakeMetricData("metricBar", // NOTE(dgryski): not sure if this matches graphite
    38  				[]float64{2, 2, 2, 2, 2}, 1, now32)},
    39  		},
    40  	}
    41  
    42  	for _, tt := range tests {
    43  		testName := tt.Target
    44  		t.Run(testName, func(t *testing.T) {
    45  			eval := th.EvaluatorFromFunc(md[0].F)
    46  			th.TestEvalExpr(t, eval, &tt)
    47  		})
    48  	}
    49  
    50  }