-
Notifications
You must be signed in to change notification settings - Fork 18
/
multirange_test.go
71 lines (69 loc) · 3.67 KB
/
multirange_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package redis_timeseries_go
import (
"reflect"
"testing"
)
func TestCreateMultiRangeCmdArguments(t *testing.T) {
type args struct {
fromTimestamp int64
toTimestamp int64
mrangeOptions MultiRangeOptions
filters []string
}
tests := []struct {
name string
args args
want []interface{}
}{
{"default",
args{0, 1, DefaultMultiRangeOptions, []string{"labels!="}},
[]interface{}{"0", "1", "FILTER", "labels!="}},
{"withlabels",
args{0, 1, *(NewMultiRangeOptions().SetWithLabels(true)),
[]string{"labels!="}},
[]interface{}{"0", "1", "WITHLABELS", "FILTER", "labels!="}},
{"withlabels and aggregation",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetWithLabels(true)),
[]string{"labels!="}},
[]interface{}{"0", "1", "AGGREGATION", AvgAggregation, "60", "WITHLABELS", "FILTER", "labels!="}},
{"withlabels, aggregation and count",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetWithLabels(true).SetCount(120)),
[]string{"labels!="}},
[]interface{}{"0", "1", "AGGREGATION", AvgAggregation, "60", "COUNT", "120", "WITHLABELS", "FILTER", "labels!="}},
{"withlabels, aggregation, count, and align",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetWithLabels(true).SetCount(120).SetAlign(10)),
[]string{"labels!="}},
[]interface{}{"0", "1", "AGGREGATION", AvgAggregation, "60", "COUNT", "120", "WITHLABELS", "ALIGN", "10", "FILTER", "labels!="}},
{"withlabels, aggregation, count, and align, filter by ts",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetWithLabels(true).SetCount(120).SetAlign(10).SetFilterByTs([]int64{10, 11, 12, 13})),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER_BY_TS", "10", "11", "12", "13", "AGGREGATION", AvgAggregation, "60", "COUNT", "120", "WITHLABELS", "ALIGN", "10", "FILTER", "labels!="}},
{"withlabels, aggregation, count, and align, filter by value",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetWithLabels(true).SetCount(120).SetAlign(10).SetFilterByValue(10, 13)),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER_BY_VALUE", "10.000000", "13.000000", "AGGREGATION", AvgAggregation, "60", "COUNT", "120", "WITHLABELS", "ALIGN", "10", "FILTER", "labels!="}},
{"selected_labels, aggregation, count, and align, filter by value",
args{0, 1, *(NewMultiRangeOptions().SetAggregation(AvgAggregation, 60).SetSelectedLabels([]string{"l1", "l2"}).SetCount(120).SetAlign(10).SetFilterByValue(10, 13)),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER_BY_VALUE", "10.000000", "13.000000", "AGGREGATION", AvgAggregation, "60", "COUNT", "120", "SELECTED_LABELS", "l1", "l2", "ALIGN", "10", "FILTER", "labels!="}},
{"groupby l2 reduce max",
args{0, 1, *NewMultiRangeOptions().SetGroupByReduce("l2", MaxReducer),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER", "labels!=", "GROUPBY", "l2", "REDUCE", "MAX"}},
{"groupby l2 reduce min",
args{0, 1, *NewMultiRangeOptions().SetGroupByReduce("l2", MinReducer),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER", "labels!=", "GROUPBY", "l2", "REDUCE", "MIN"}},
{"groupby l2 reduce sum",
args{0, 1, *NewMultiRangeOptions().SetGroupByReduce("l2", SumReducer),
[]string{"labels!="}},
[]interface{}{"0", "1", "FILTER", "labels!=", "GROUPBY", "l2", "REDUCE", "SUM"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := createMultiRangeCmdArguments(tt.args.fromTimestamp, tt.args.toTimestamp, tt.args.mrangeOptions, tt.args.filters); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CreateMultiRangeCmdArguments() = %v, want %v", got, tt.want)
}
})
}
}