Skip to content

Commit a674d4d

Browse files
authored
CLOUDP-261049: Fix search e2e tests (#3093)
1 parent 9bf74d5 commit a674d4d

File tree

1 file changed

+131
-124
lines changed

1 file changed

+131
-124
lines changed

test/e2e/atlas/search_test.go

Lines changed: 131 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ func TestSearch(t *testing.T) {
7070
"collectionName": "{{ .collectionName }}",
7171
"database": "test",
7272
"name": "{{ .indexName }}",
73-
"mappings": {
74-
"dynamic": true
73+
"definition": {
74+
"mappings": {
75+
"dynamic": true
76+
}
7577
}
7678
}`))
7779
require.NoError(t, tpl.Execute(file, map[string]string{
@@ -93,7 +95,7 @@ func TestSearch(t *testing.T) {
9395
cmd.Env = os.Environ()
9496
resp, err := e2e.RunAndGetStdOut(cmd)
9597
require.NoError(t, err, string(resp))
96-
var index atlasv2.ClusterSearchIndex
98+
var index atlasv2.SearchIndexResponse
9799
require.NoError(t, json.Unmarshal(resp, &index))
98100
assert.Equal(t, index.GetName(), indexName)
99101
indexID = index.GetIndexID()
@@ -112,7 +114,7 @@ func TestSearch(t *testing.T) {
112114
cmd.Env = os.Environ()
113115
resp, err := e2e.RunAndGetStdOut(cmd)
114116
require.NoError(t, err, string(resp))
115-
var index atlasv2.ClusterSearchIndex
117+
var index atlasv2.SearchIndexResponse
116118
require.NoError(t, json.Unmarshal(resp, &index))
117119
assert.Equal(t, indexID, index.GetIndexID())
118120
})
@@ -126,15 +128,13 @@ func TestSearch(t *testing.T) {
126128
t.Cleanup(func() {
127129
require.NoError(t, os.Remove(fileName))
128130
})
129-
130131
tpl := template.Must(template.New("").Parse(`
131132
{
132-
"collectionName": "{{ .collectionName }}",
133-
"database": "test",
134-
"name": "{{ .indexName }}",
135-
"analyzer": "{{ .analyzer }}",
136-
"mappings": {
137-
"dynamic": true
133+
"definition": {
134+
"analyzer": "{{ .analyzer }}",
135+
"mappings": {
136+
"dynamic": true
137+
}
138138
}
139139
}`))
140140
require.NoError(t, tpl.Execute(file, map[string]string{
@@ -158,11 +158,12 @@ func TestSearch(t *testing.T) {
158158
cmd.Env = os.Environ()
159159
resp, err := e2e.RunAndGetStdOut(cmd)
160160
require.NoError(t, err, string(resp))
161-
var index atlasv2.ClusterSearchIndex
161+
var index atlasv2.SearchIndexResponse
162162
require.NoError(t, json.Unmarshal(resp, &index))
163163
a := assert.New(t)
164164
a.Equal(indexID, index.GetIndexID())
165-
a.Equal(analyzer, index.GetAnalyzer())
165+
def := index.GetLatestDefinition()
166+
a.Equal(analyzer, def.GetAnalyzer())
166167
})
167168

168169
t.Run("Delete", func(t *testing.T) {
@@ -196,31 +197,33 @@ func TestSearch(t *testing.T) {
196197
"collectionName": "planets",
197198
"database": "sample_guides",
198199
"name": "{{ .indexName }}",
199-
"analyzer": "lucene.standard",
200-
"searchAnalyzer": "lucene.standard",
201-
"mappings": {
202-
"dynamic": false,
203-
"fields": {
204-
"name": {
205-
"type": "string",
206-
"analyzer": "lucene.whitespace",
207-
"multi": {
208-
"mySecondaryAnalyzer": {
209-
"type": "string",
210-
"analyzer": "lucene.french"
211-
}
212-
}
213-
},
214-
"mainAtmosphere": {
215-
"type": "string",
216-
"analyzer": "lucene.standard"
217-
},
218-
"surfaceTemperatureC": {
219-
"type": "document",
220-
"dynamic": true,
221-
"analyzer": "lucene.standard"
222-
}
223-
}
200+
"definition": {
201+
"analyzer": "lucene.standard",
202+
"searchAnalyzer": "lucene.standard",
203+
"mappings": {
204+
"dynamic": false,
205+
"fields": {
206+
"name": {
207+
"type": "string",
208+
"analyzer": "lucene.whitespace",
209+
"multi": {
210+
"mySecondaryAnalyzer": {
211+
"type": "string",
212+
"analyzer": "lucene.french"
213+
}
214+
}
215+
},
216+
"mainAtmosphere": {
217+
"type": "string",
218+
"analyzer": "lucene.standard"
219+
},
220+
"surfaceTemperatureC": {
221+
"type": "document",
222+
"dynamic": true,
223+
"analyzer": "lucene.standard"
224+
}
225+
}
226+
}
224227
}
225228
}`))
226229
require.NoError(t, tpl.Execute(file, map[string]string{
@@ -241,9 +244,9 @@ func TestSearch(t *testing.T) {
241244
cmd.Env = os.Environ()
242245
resp, err := e2e.RunAndGetStdOut(cmd)
243246
require.NoError(t, err, string(resp))
244-
var index atlasv2.ClusterSearchIndex
247+
var index atlasv2.SearchIndexResponse
245248
require.NoError(t, json.Unmarshal(resp, &index))
246-
assert.Equal(t, indexName, index.Name)
249+
assert.Equal(t, indexName, index.GetName())
247250
})
248251

249252
t.Run("Create staticMapping", func(t *testing.T) {
@@ -260,71 +263,73 @@ func TestSearch(t *testing.T) {
260263
"collectionName": "posts",
261264
"database": "sample_training",
262265
"name": "{{ .indexName }}",
263-
"analyzer": "lucene.standard",
264-
"searchAnalyzer": "lucene.standard",
265-
"mappings": {
266-
"dynamic": false,
267-
"fields": {
268-
"comments": {
269-
"type": "document",
270-
"fields": {
271-
"body": {
272-
"type": "string",
273-
"analyzer": "lucene.simple",
274-
"ignoreAbove": 255
275-
},
276-
"author": {
277-
"type": "string",
278-
"analyzer": "keywordLowerCase"
279-
}
280-
}
281-
},
282-
"body": {
283-
"type": "string",
284-
"analyzer": "lucene.whitespace",
285-
"multi": {
286-
"mySecondaryAnalyzer": {
287-
"type": "string",
288-
"analyzer": "keywordLowerCase"
289-
}
290-
}
291-
},
292-
"tags": {
293-
"type": "string",
294-
"analyzer": "standardLowerCase"
295-
}
296-
}
297-
},
298-
"analyzers":[
299-
{
300-
"charFilters":[
301-
302-
],
303-
"name":"keywordLowerCase",
304-
"tokenFilters":[
305-
{
306-
"type":"lowercase"
307-
}
308-
],
309-
"tokenizer":{
310-
"type":"keyword"
311-
}
312-
},
313-
{
314-
"charFilters":[
315-
316-
],
317-
"name":"standardLowerCase",
318-
"tokenFilters":[
319-
{
320-
"type":"lowercase"
321-
}
322-
],
323-
"tokenizer":{
324-
"type":"standard"
325-
}
326-
}
327-
]
266+
"definition": {
267+
"analyzer": "lucene.standard",
268+
"searchAnalyzer": "lucene.standard",
269+
"mappings": {
270+
"dynamic": false,
271+
"fields": {
272+
"comments": {
273+
"type": "document",
274+
"fields": {
275+
"body": {
276+
"type": "string",
277+
"analyzer": "lucene.simple",
278+
"ignoreAbove": 255
279+
},
280+
"author": {
281+
"type": "string",
282+
"analyzer": "keywordLowerCase"
283+
}
284+
}
285+
},
286+
"body": {
287+
"type": "string",
288+
"analyzer": "lucene.whitespace",
289+
"multi": {
290+
"mySecondaryAnalyzer": {
291+
"type": "string",
292+
"analyzer": "keywordLowerCase"
293+
}
294+
}
295+
},
296+
"tags": {
297+
"type": "string",
298+
"analyzer": "standardLowerCase"
299+
}
300+
}
301+
},
302+
"analyzers":[
303+
{
304+
"charFilters":[
305+
306+
],
307+
"name":"keywordLowerCase",
308+
"tokenFilters":[
309+
{
310+
"type":"lowercase"
311+
}
312+
],
313+
"tokenizer":{
314+
"type":"keyword"
315+
}
316+
},
317+
{
318+
"charFilters":[
319+
320+
],
321+
"name":"standardLowerCase",
322+
"tokenFilters":[
323+
{
324+
"type":"lowercase"
325+
}
326+
],
327+
"tokenizer":{
328+
"type":"standard"
329+
}
330+
}
331+
]
332+
}
328333
}`))
329334
require.NoError(t, tpl.Execute(file, map[string]string{
330335
"indexName": indexName,
@@ -344,9 +349,9 @@ func TestSearch(t *testing.T) {
344349
cmd.Env = os.Environ()
345350
resp, err := e2e.RunAndGetStdOut(cmd)
346351
require.NoError(t, err, string(resp))
347-
var index atlasv2.ClusterSearchIndex
352+
var index atlasv2.SearchIndexResponse
348353
require.NoError(t, json.Unmarshal(resp, &index))
349-
assert.Equal(t, indexName, index.Name)
354+
assert.Equal(t, indexName, index.GetName())
350355
})
351356

352357
t.Run("Create array mapping", func(t *testing.T) {
@@ -366,20 +371,22 @@ func TestSearch(t *testing.T) {
366371
"collectionName": "posts",
367372
"database": "sample_training",
368373
"name": "{{ .indexName }}",
369-
"analyzer": "lucene.standard",
370-
"searchAnalyzer": "lucene.standard",
371-
"mappings": {
372-
"dynamic": false,
373-
"fields": {
374-
"comments": [
375-
{
376-
"dynamic": true,
377-
"type": "document"
378-
},
379-
{
380-
"type": "string"
381-
}]
382-
}
374+
"definition": {
375+
"analyzer": "lucene.standard",
376+
"searchAnalyzer": "lucene.standard",
377+
"mappings": {
378+
"dynamic": false,
379+
"fields": {
380+
"comments": [
381+
{
382+
"dynamic": true,
383+
"type": "document"
384+
},
385+
{
386+
"type": "string"
387+
}]
388+
}
389+
}
383390
}
384391
}`))
385392
require.NoError(t, tpl.Execute(file, map[string]string{
@@ -400,9 +407,9 @@ func TestSearch(t *testing.T) {
400407
cmd.Env = os.Environ()
401408
resp, err := e2e.RunAndGetStdOut(cmd)
402409
require.NoError(t, err, string(resp))
403-
var index atlasv2.ClusterSearchIndex
410+
var index atlasv2.SearchIndexResponse
404411
require.NoError(t, json.Unmarshal(resp, &index))
405-
assert.Equal(t, indexName, index.Name)
412+
assert.Equal(t, indexName, index.GetName())
406413
})
407414

408415
t.Run("list", func(t *testing.T) {
@@ -421,7 +428,7 @@ func TestSearch(t *testing.T) {
421428
resp, err := e2e.RunAndGetStdOut(cmd)
422429
require.NoError(t, err, string(resp))
423430

424-
var indexes []atlasv2.ClusterSearchIndex
431+
var indexes []atlasv2.SearchIndexResponse
425432
require.NoError(t, json.Unmarshal(resp, &indexes))
426433
assert.NotEmpty(t, indexes)
427434
})

0 commit comments

Comments
 (0)