github.com/go-graphite/carbonapi@v0.17.0/expr/helper/metric/extract_test.go (about)

     1  package metric
     2  
     3  import "testing"
     4  
     5  func TestExtractMetric(t *testing.T) {
     6  	var tests = []struct {
     7  		input  string
     8  		metric string
     9  	}{
    10  		{
    11  			"f",
    12  			"f",
    13  		},
    14  		{
    15  			"func(f)",
    16  			"f",
    17  		},
    18  		{
    19  			"foo.bar.baz",
    20  			"foo.bar.baz",
    21  		},
    22  		{
    23  			"nonNegativeDerivative(foo.bar.baz)",
    24  			"foo.bar.baz",
    25  		},
    26  		{
    27  			"movingAverage(foo.bar.baz,10)",
    28  			"foo.bar.baz",
    29  		},
    30  		{
    31  			"scale(scaleToSeconds(nonNegativeDerivative(foo.bar.baz),60),60)",
    32  			"foo.bar.baz",
    33  		},
    34  		{
    35  			"divideSeries(foo.bar.baz,baz.qux.zot)",
    36  			"foo.bar.baz",
    37  		},
    38  		{
    39  			"{something}",
    40  			"{something}",
    41  		},
    42  	}
    43  
    44  	for _, tt := range tests {
    45  		t.Run(tt.input, func(t *testing.T) {
    46  			if m := ExtractMetric(tt.input); m != tt.metric {
    47  				t.Errorf("extractMetric(%q)=%q, want %q", tt.input, m, tt.metric)
    48  			}
    49  		})
    50  	}
    51  }