-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter_retention_policy_test.go
121 lines (114 loc) · 3.21 KB
/
alter_retention_policy_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
package influxqb
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
var testAlterRetentionPolicy = []struct {
d string
b BuilderIf
s string
e bool
}{
{
"Simple Retention policy",
NewAlterRetentionPolicyBuilder().WithPolicyName("PolicyName").WithDatabase("database"),
"ALTER RETENTION POLICY PolicyName ON \"database\"",
false,
},
{
"Simple Retention policy set default",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
SetAsDefault(),
"ALTER RETENTION POLICY PolicyName ON \"database\" DEFAULT",
false,
},
{
"Simple Retention policy set duration",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithDurationString("1h"),
"ALTER RETENTION POLICY PolicyName ON \"database\" DURATION 1h",
false,
},
{
"Simple Retention policy set shard duration",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h"),
"ALTER RETENTION POLICY PolicyName ON \"database\" SHARD DURATION 1h",
false,
},
{
"Simple Retention policy set shard duration and duration",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h").
WithDurationString("3h"),
"ALTER RETENTION POLICY PolicyName ON \"database\" DURATION 3h SHARD DURATION 1h",
false,
},
{
"Simple Retention policy set shard duration and duration plus replication factor",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h").
WithDurationString("3h").
WithReplicationFactor(36),
"ALTER RETENTION POLICY PolicyName ON \"database\" DURATION 3h REPLICATION 36 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy unicode names and quotes",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName↔").
WithDatabase("datab'ase").
WithShardDurationString("1h").
WithDurationString("3h").
WithReplicationFactor(36),
"ALTER RETENTION POLICY \"PolicyName↔\" ON \"datab'ase\" DURATION 3h REPLICATION 36 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy invalid duration",
NewAlterRetentionPolicyBuilder().
WithPolicyName("PolicyName↔").
WithDatabase("datab'ase").
WithShardDurationString("notValid").
WithDurationString("notValid").
WithReplicationFactor(36),
"ALTER RETENTION POLICY \"PolicyName↔\" ON \"datab'ase\" DURATION 0s REPLICATION 36 SHARD DURATION 0s",
false,
},
{
"Alter with future and past limits",
NewAlterRetentionPolicyBuilder().
WithPolicyName("default").
WithDatabase("testdb").
WithDurationString("0s").
WithReplicationFactor(1).
WithFutureLimitString("55s").
WithPastLimitString("52m"),
"ALTER RETENTION POLICY \"default\" ON testdb DURATION 0s REPLICATION 1 FUTURE LIMIT 55s PAST LIMIT 52m",
false,
},
}
func TestAlterRetentionPolicyBuilder(t *testing.T) {
for i, sample := range testAlterRetentionPolicy {
s, err := sample.b.Build()
fmt.Print("Test ", i, ": ", sample.d)
if sample.e {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, sample.s, s)
fmt.Println(" [OK]")
}
}