-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdownsample_test.go
132 lines (121 loc) · 4.04 KB
/
downsample_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package redists
import (
"context"
"fmt"
"reflect"
"testing"
"time"
)
func TestCmdCreateRule(t *testing.T) {
t.Run("basic", func(t *testing.T) {
cmd := newCmdCreateRule("key:src", "key:dst", AggregationTypeAvg, time.Second)
if got, want := cmd.Name(), "TS.CREATERULE"; got != want {
t.Errorf("Name() = %v, want %v", got, want)
}
if got, want := cmd.Args(), []interface{}{"key:src", "key:dst", "AGGREGATION", "AVG", int64(1000)}; !reflect.DeepEqual(got, want) {
t.Errorf("Args() = %v, want %v", got, want)
}
})
t.Run("align timestamp", func(t *testing.T) {
cmd := newCmdCreateRule("key:src", "key:dst", AggregationTypeAvg, time.Second)
CreateRuleWithAlignTimestamp(time.UnixMilli(1001))(cmd)
if got, want := cmd.Args(), []interface{}{"key:src", "key:dst", "AGGREGATION", "AVG", int64(1000), int64(1001)}; !reflect.DeepEqual(got, want) {
t.Errorf("Args() = %v, want %v", got, want)
}
})
}
func TestClient_CreateRule(t *testing.T) {
if testing.Short() {
t.Skip("skip client test")
}
for _, tt := range doerTests {
t.Run(tt.name, func(t *testing.T) {
srcKey := fmt.Sprintf("example:src:%s", t.Name())
destKey := fmt.Sprintf("example:dest:%s", t.Name())
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
doer, err := tt.doer(ctx)
if err != nil {
t.Fatal(err)
}
defer doer.Close()
defer doer.Do(context.Background(), "DEL", srcKey, destKey)
tsclient := NewClient(doer)
if err = tsclient.Create(ctx, srcKey); err != nil {
t.Fatalf("Create() error = %v", err)
}
if err := tsclient.Create(ctx, destKey); err != nil {
t.Fatalf("Create() error = %v", err)
}
if err = tsclient.CreateRule(ctx, srcKey, destKey, AggregationTypeAvg, time.Minute); err != nil {
t.Fatalf("CreateRule() error = %v", err)
}
inf, err := tsclient.Info(ctx, srcKey)
if err != nil {
t.Fatalf("Info() error = %v", err)
}
want := Rules{destKey: Aggregation{AggregationTypeAvg, time.Minute}}
if got, want := inf.Rules, want; !reflect.DeepEqual(got, want) {
t.Errorf("Info().Rules got = %v, want %v", got, want)
}
})
}
}
func TestCmdDeleteRule(t *testing.T) {
t.Run("basic", func(t *testing.T) {
cmd := newCmdDeleteRule("key:src", "key:dst")
if got, want := cmd.Name(), "TS.DELETERULE"; got != want {
t.Errorf("Name() = %v, want %v", got, want)
}
if got, want := cmd.Args(), []interface{}{"key:src", "key:dst"}; !reflect.DeepEqual(got, want) {
t.Errorf("Args() = %v, want %v", got, want)
}
})
}
func TestClient_DeleteRule(t *testing.T) {
if testing.Short() {
t.Skip("skip client test")
}
for _, tt := range doerTests {
t.Run(tt.name, func(t *testing.T) {
srcKey := fmt.Sprintf("example:src:%s", t.Name())
destKey := fmt.Sprintf("example:dest:%s", t.Name())
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
doer, err := tt.doer(ctx)
if err != nil {
t.Fatal(err)
}
defer doer.Close()
defer doer.Do(context.Background(), "DEL", srcKey, destKey)
tsclient := NewClient(doer)
if err = tsclient.Create(ctx, srcKey); err != nil {
t.Fatalf("Create() error = %v", err)
}
if err := tsclient.Create(ctx, destKey); err != nil {
t.Fatalf("Create() error = %v", err)
}
if err = tsclient.CreateRule(ctx, srcKey, destKey, AggregationTypeAvg, time.Minute); err != nil {
t.Fatalf("CreateRule() error = %v", err)
}
inf, err := tsclient.Info(ctx, srcKey)
if err != nil {
t.Fatalf("Info() error = %v", err)
}
want := Rules{destKey: Aggregation{AggregationTypeAvg, time.Minute}}
if got, want := inf.Rules, want; !reflect.DeepEqual(got, want) {
t.Errorf("Info().Rules got = %v, want %v", got, want)
}
if err = tsclient.DeleteRule(ctx, srcKey, destKey); err != nil {
t.Fatalf("DeleteRule() error = %v", err)
}
inf, err = tsclient.Info(ctx, srcKey)
if err != nil {
t.Fatalf("Info() error = %v", err)
}
if got, want := inf.Rules, (Rules{}); !reflect.DeepEqual(got, want) {
t.Errorf("Info().Rules got = %v, want %v", got, want)
}
})
}
}