-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_retention_policy_test.go
121 lines (114 loc) · 3.37 KB
/
create_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 testCreateRetentionPolicy = []struct {
d string
b BuilderIf
s string
e bool
}{
{
"Simple Retention policy",
NewCreateRetentionPolicyBuilder().WithPolicyName("PolicyName").WithDatabase("database"),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 0s REPLICATION 0",
false,
},
{
"Simple Retention policy set default",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
SetAsDefault(),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 0s REPLICATION 0 DEFAULT",
false,
},
{
"Simple Retention policy set duration",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithDurationString("1h"),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 1h REPLICATION 0",
false,
},
{
"Simple Retention policy set shard duration",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h"),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 0s REPLICATION 0 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy set shard duration and duration",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h").
WithDurationString("3h"),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 3h REPLICATION 0 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy set shard duration and duration plus replication factor",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName").
WithDatabase("database").
WithShardDurationString("1h").
WithDurationString("3h").
WithReplicationFactor(36),
"CREATE RETENTION POLICY PolicyName ON \"database\" DURATION 3h REPLICATION 36 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy unicode names and quotes",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName↔").
WithDatabase("datab'ase").
WithShardDurationString("1h").
WithDurationString("3h").
WithReplicationFactor(36),
"CREATE RETENTION POLICY \"PolicyName↔\" ON \"datab'ase\" DURATION 3h REPLICATION 36 SHARD DURATION 1h",
false,
},
{
"Simple Retention policy invalid duration",
NewCreateRetentionPolicyBuilder().
WithPolicyName("PolicyName↔").
WithDatabase("datab'ase").
WithShardDurationString("notValid").
WithDurationString("notValid").
WithReplicationFactor(36),
"CREATE RETENTION POLICY \"PolicyName↔\" ON \"datab'ase\" DURATION 0s REPLICATION 36",
false,
},
{
"Retention policy with future and past limit",
NewCreateRetentionPolicyBuilder().WithPolicyName("policy1").
WithDatabase("testdb").
WithDurationString("1h").
WithReplicationFactor(2).
WithShardDurationString("1s").
WithFutureLimitString("12h").
WithPastLimitString("3s"),
"CREATE RETENTION POLICY policy1 ON testdb DURATION 1h REPLICATION 2 SHARD DURATION 1s FUTURE LIMIT 12h PAST LIMIT 3s",
false,
},
}
func TestCreateRetentionPolicyBuilder(t *testing.T) {
for i, sample := range testCreateRetentionPolicy {
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]")
}
}