-
Notifications
You must be signed in to change notification settings - Fork 104
/
cluster_analyticsindexes_test.go
207 lines (173 loc) · 5.15 KB
/
cluster_analyticsindexes_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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package gocb
import (
"errors"
"testing"
)
func TestAnalyticsIndexesCrud(t *testing.T) {
if !globalCluster.SupportsFeature(AnalyticsIndexFeature) {
t.Skip("Skipping test, analytics indexes not supported.")
}
mgr, err := globalCluster.AnalyticsIndexes()
if err != nil {
t.Fatalf("Expected AnalyticsIndexes to not error %v", err)
}
err = mgr.CreateDataverse("testaverse", nil)
if err != nil {
t.Fatalf("Expected CreateDataverse to not error %v", err)
}
err = mgr.CreateDataverse("testaverse", &CreateAnalyticsDataverseOptions{
IgnoreIfExists: true,
})
if err != nil {
t.Fatalf("Expected CreateDataverse to not error %v", err)
}
err = mgr.CreateDataverse("testaverse", nil)
if err == nil {
t.Fatalf("Expected CreateDataverse to error")
}
if !errors.Is(err, ErrDataverseExists) {
t.Fatalf("Expected error to be dataverse already exists but was %v", err)
}
err = mgr.CreateDataset("testaset", globalBucket.Name(), &CreateAnalyticsDatasetOptions{
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected CreateDataset to not error %v", err)
}
err = mgr.CreateDataset("testaset", globalBucket.Name(), &CreateAnalyticsDatasetOptions{
IgnoreIfExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected CreateDataset to not error %v", err)
}
err = mgr.CreateDataset("testaset", globalBucket.Name(), &CreateAnalyticsDatasetOptions{
DataverseName: "testaverse",
})
if err == nil {
t.Fatalf("Expected CreateDataverse to error")
}
if !errors.Is(err, ErrDatasetExists) {
t.Fatalf("Expected error to be dataset already exists but was %v", err)
}
err = mgr.CreateIndex("testaset", "testindex", map[string]string{
"testkey": "string",
}, &CreateAnalyticsIndexOptions{
IgnoreIfExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected CreateIndex to not error %v", err)
}
err = mgr.CreateIndex("testaset", "testindex", map[string]string{
"testkey": "string",
}, &CreateAnalyticsIndexOptions{
IgnoreIfExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected CreateIndex to not error %v", err)
}
err = mgr.CreateIndex("testaset", "testindex", map[string]string{
"testkey": "string",
}, &CreateAnalyticsIndexOptions{
IgnoreIfExists: false,
DataverseName: "testaverse",
})
if err == nil {
t.Fatalf("Expected CreateIndex to error")
}
if !errors.Is(err, ErrIndexExists) {
t.Fatalf("Expected error to be index already exists but was %v", err)
}
err = mgr.ConnectLink(nil)
if err != nil {
t.Fatalf("Expected ConnectLink to not error %v", err)
}
datasets, err := mgr.GetAllDatasets(nil)
if err != nil {
t.Fatalf("Expected GetAllDatasets to not error %v", err)
}
if len(datasets) == 0 {
t.Fatalf("Expected datasets length to be greater than 0")
}
indexes, err := mgr.GetAllIndexes(nil)
if err != nil {
t.Fatalf("Expected GetAllIndexes to not error %v", err)
}
if len(indexes) == 0 {
t.Fatalf("Expected indexes length to be greater than 0")
}
if globalCluster.SupportsFeature(AnalyticsIndexPendingMutationsFeature) {
_, err = mgr.GetPendingMutations(nil)
if err != nil {
t.Fatalf("Expected GetPendingMutations to not error %v", err)
}
}
err = mgr.DisconnectLink(nil)
if err != nil {
t.Fatalf("Expected DisconnectLink to not error %v", err)
}
err = mgr.DropIndex("testaset", "testindex", &DropAnalyticsIndexOptions{
IgnoreIfNotExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected DropIndex to not error %v", err)
}
err = mgr.DropIndex("testaset", "testindex", &DropAnalyticsIndexOptions{
IgnoreIfNotExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected DropIndex to not error %v", err)
}
err = mgr.DropIndex("testaset", "testindex", &DropAnalyticsIndexOptions{
DataverseName: "testaverse",
})
if err == nil {
t.Fatalf("Expected DropIndex to error")
}
if !errors.Is(err, ErrIndexNotFound) {
t.Fatalf("Expected error to be index not found but was %v", err)
}
err = mgr.DropDataset("testaset", &DropAnalyticsDatasetOptions{
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected DropDataset to not error %v", err)
}
err = mgr.DropDataset("testaset", &DropAnalyticsDatasetOptions{
IgnoreIfNotExists: true,
DataverseName: "testaverse",
})
if err != nil {
t.Fatalf("Expected DropDataset to not error %v", err)
}
err = mgr.DropDataset("testaset", &DropAnalyticsDatasetOptions{
DataverseName: "testaverse",
})
if err == nil {
t.Fatalf("Expected DropDataset to error")
}
if !errors.Is(err, ErrDatasetNotFound) {
t.Fatalf("Expected error to be dataset not found but was %v", err)
}
err = mgr.DropDataverse("testaverse", nil)
if err != nil {
t.Fatalf("Expected DropDataverse to not error %v", err)
}
err = mgr.DropDataverse("testaverse", &DropAnalyticsDataverseOptions{
IgnoreIfNotExists: true,
})
if err != nil {
t.Fatalf("Expected DropDataverse to not error %v", err)
}
err = mgr.DropDataverse("testaverse", nil)
if err == nil {
t.Fatalf("Expected DropDataverse to error")
}
if !errors.Is(err, ErrDataverseNotFound) {
t.Fatalf("Expected error to be dataverse not found but was %v", err)
}
}