Skip to content

Commit 5c4c0ee

Browse files
list search index tests working on atlas
1 parent be11dc8 commit 5c4c0ee

File tree

7 files changed

+95
-55
lines changed

7 files changed

+95
-55
lines changed

test/manual/search-index-management.spec.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ import { loadSpecTests } from '../spec';
44
import { runUnifiedSuite } from '../tools/unified-spec-runner/runner';
55

66
describe('Search Index Management Tests (Unified)', function () {
7-
runUnifiedSuite(loadSpecTests(join('index-management')));
7+
before(function () {
8+
this.configuration = this.configuration.makeAtlasTestConfiguration();
9+
});
10+
runUnifiedSuite(loadSpecTests(join('index-management')), test =>
11+
test.description.includes('test') ? false : 'skipped'
12+
);
813
});

test/spec/index-management/listSearchIndexes.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
},
1414
{
1515
"database": {
16-
"id": "database0",
16+
"id": "shared",
1717
"client": "client0",
18-
"databaseName": "database0"
18+
"databaseName": "shared"
1919
}
2020
},
2121
{
2222
"collection": {
23-
"id": "collection0",
24-
"database": "database0",
25-
"collectionName": "collection0"
23+
"id": "list-search-indexes",
24+
"database": "shared",
25+
"collectionName": "list-search-indexes"
2626
}
2727
}
2828
],
@@ -34,19 +34,22 @@
3434
"load-balanced",
3535
"sharded"
3636
],
37-
"serverless": "forbid"
37+
"serverless": "forbid",
38+
"atlas": true
3839
}
3940
],
4041
"tests": [
4142
{
42-
"description": "when no name is provided, it does not populate the filter",
43+
"description": "test when no name is provided, it does not populate the filter",
4344
"operations": [
4445
{
4546
"name": "listSearchIndexes",
46-
"object": "collection0",
47-
"expectError": {
48-
"isError": true
49-
}
47+
"object": "list-search-indexes",
48+
"expectResult": [
49+
{
50+
"name": "default"
51+
}
52+
]
5053
}
5154
],
5255
"expectEvents": [
@@ -56,7 +59,7 @@
5659
{
5760
"commandStartedEvent": {
5861
"command": {
59-
"aggregate": "collection0",
62+
"aggregate": "list-search-indexes",
6063
"pipeline": [
6164
{
6265
"$listSearchIndexes": {}
@@ -70,17 +73,15 @@
7073
]
7174
},
7275
{
73-
"description": "when a name is provided, it is present in the filter",
76+
"description": "test when a name is provided, it is present in the filter",
7477
"operations": [
7578
{
7679
"name": "listSearchIndexes",
77-
"object": "collection0",
80+
"object": "list-search-indexes",
7881
"arguments": {
79-
"name": "test index"
82+
"name": "test-index"
8083
},
81-
"expectError": {
82-
"isError": true
83-
}
84+
"expectResult": []
8485
}
8586
],
8687
"expectEvents": [
@@ -90,15 +91,15 @@
9091
{
9192
"commandStartedEvent": {
9293
"command": {
93-
"aggregate": "collection0",
94+
"aggregate": "list-search-indexes",
9495
"pipeline": [
9596
{
9697
"$listSearchIndexes": {
97-
"name": "test index"
98+
"name": "test-index"
9899
}
99100
}
100101
],
101-
"$db": "database0"
102+
"$db": "shared"
102103
}
103104
}
104105
}
@@ -107,20 +108,21 @@
107108
]
108109
},
109110
{
110-
"description": "aggregation cursor options are supported",
111+
"description": "test aggregation cursor options are supported",
111112
"operations": [
112113
{
113114
"name": "listSearchIndexes",
114-
"object": "collection0",
115+
"object": "list-search-indexes",
115116
"arguments": {
116-
"name": "test index",
117117
"aggregationOptions": {
118118
"batchSize": 10
119119
}
120120
},
121-
"expectError": {
122-
"isError": true
123-
}
121+
"expectResult": [
122+
{
123+
"name": "default"
124+
}
125+
]
124126
}
125127
],
126128
"expectEvents": [
@@ -130,18 +132,16 @@
130132
{
131133
"commandStartedEvent": {
132134
"command": {
133-
"aggregate": "collection0",
135+
"aggregate": "list-search-indexes",
134136
"cursor": {
135137
"batchSize": 10
136138
},
137139
"pipeline": [
138140
{
139-
"$listSearchIndexes": {
140-
"name": "test index"
141-
}
141+
"$listSearchIndexes": {}
142142
}
143143
],
144-
"$db": "database0"
144+
"$db": "shared"
145145
}
146146
}
147147
}
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# yaml-language-server: $schema=/Users/bailey.pearson/dev/specifications/source/unified-test-format/schema-1.15.json
2+
13
description: "listSearchIndexes"
24
schemaVersion: "1.4"
35
createEntities:
@@ -7,28 +9,27 @@ createEntities:
79
observeEvents:
810
- commandStartedEvent
911
- database:
10-
id: &database0 database0
12+
id: &database0 shared
1113
client: *client0
1214
databaseName: *database0
1315
- collection:
14-
id: &collection0 collection0
16+
id: &collection0 list-search-indexes
1517
database: *database0
1618
collectionName: *collection0
1719

1820
runOnRequirements:
1921
- minServerVersion: "7.0.0"
2022
topologies: [ replicaset, load-balanced, sharded ]
2123
serverless: forbid
24+
atlas: true
2225

2326
tests:
24-
- description: "when no name is provided, it does not populate the filter"
27+
- description: "test when no name is provided, it does not populate the filter"
2528
operations:
2629
- name: listSearchIndexes
2730
object: *collection0
28-
expectError:
29-
# Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing
30-
# against an Atlas cluster and the expectError will be removed.
31-
isError: true
31+
expectResult: [ { name: default } ]
32+
3233
expectEvents:
3334
- client: *client0
3435
events:
@@ -38,16 +39,14 @@ tests:
3839
pipeline:
3940
- $listSearchIndexes: {}
4041

41-
- description: "when a name is provided, it is present in the filter"
42+
- description: "test when a name is provided, it is present in the filter"
4243
operations:
4344
- name: listSearchIndexes
4445
object: *collection0
4546
arguments:
46-
name: &indexName "test index"
47-
expectError:
48-
# Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing
49-
# against an Atlas cluster and the expectError will be removed.
50-
isError: true
47+
name: &indexName "test-index"
48+
expectResult: []
49+
5150
expectEvents:
5251
- client: *client0
5352
events:
@@ -58,18 +57,15 @@ tests:
5857
- $listSearchIndexes: { name: *indexName }
5958
$db: *database0
6059

61-
- description: aggregation cursor options are supported
60+
- description: test aggregation cursor options are supported
6261
operations:
6362
- name: listSearchIndexes
6463
object: *collection0
6564
arguments:
66-
name: &indexName "test index"
6765
aggregationOptions:
6866
batchSize: 10
69-
expectError:
70-
# Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing
71-
# against an Atlas cluster and the expectError will be removed.
72-
isError: true
67+
expectResult: [ { name: default } ]
68+
7369
expectEvents:
7470
- client: *client0
7571
events:
@@ -78,5 +74,5 @@ tests:
7874
aggregate: *collection0
7975
cursor: { batchSize: 10 }
8076
pipeline:
81-
- $listSearchIndexes: { name: *indexName }
77+
- $listSearchIndexes: { }
8278
$db: *database0

test/tools/runner/config.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export class TestConfiguration {
7272
proxyURIParams?: ProxyParams;
7373
};
7474
serverApi: string;
75+
isAtlas: boolean;
7576

76-
constructor(uri: string, context: Record<string, any>) {
77+
constructor(private uri: string, private context: Record<string, any>) {
7778
const url = new ConnectionString(uri);
7879
const { hosts } = url;
7980
const hostAddresses = hosts.map(HostAddress.fromString);
@@ -116,6 +117,7 @@ export class TestConfiguration {
116117
const { username, password } = context.serverlessCredentials;
117118
this.options.auth = { username, password, authSource: 'admin' };
118119
}
120+
this.isAtlas = process.env.IS_ATLAS === 'true';
119121
}
120122

121123
get isLoadBalanced() {
@@ -358,4 +360,23 @@ export class TestConfiguration {
358360
kmsProviders(localKey): Record<string, any> {
359361
return { local: { key: localKey } };
360362
}
363+
364+
makeAtlasTestConfiguration(): AtlasTestConfiguration {
365+
return new AtlasTestConfiguration(this.uri, this.context);
366+
}
367+
}
368+
369+
/**
370+
* A specialized configuration used to connect to Atlas for testing.
371+
*
372+
* This class requires that the Atlas srv URI is set as the `MONGODB_URI` in the environment.
373+
*/
374+
export class AtlasTestConfiguration extends TestConfiguration {
375+
override newClient(): MongoClient {
376+
return new MongoClient(process.env.MONGODB_URI!);
377+
}
378+
379+
override url(): string {
380+
return process.env.MONGODB_URI!;
381+
}
361382
}

test/tools/unified-spec-runner/match.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ export function resultCheck(
220220
}
221221

222222
if (typeof actual !== 'object') {
223-
expect.fail('Expected actual value to be an object');
223+
const error = { expected, actual, path };
224+
expect.fail(
225+
`Error matching. Expected an object but received something else. ${inspect(error)}`
226+
);
224227
}
225228

226229
const expectedEntries = Object.entries(expected);

test/tools/unified-spec-runner/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export interface RunOnRequirement {
114114
topologies?: TopologyId[];
115115
serverParameters?: Document;
116116
csfle?: boolean;
117+
atlas?: boolean;
117118
}
118119
export type ObservableCommandEventId =
119120
| 'commandStartedEvent'

test/tools/unified-spec-runner/unified-utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ export async function topologySatisfies(
132132
}
133133
}
134134

135+
if (typeof r.atlas === 'boolean') {
136+
if (r.atlas) {
137+
ok &&= config.isAtlas;
138+
if (!ok) {
139+
skipReason = `Tests must be connected to atlas.`;
140+
}
141+
} else {
142+
ok &&= !config.isAtlas;
143+
if (!ok) {
144+
skipReason = `Tests must NOT be connected to atlas.`;
145+
}
146+
}
147+
}
148+
135149
if (!ok && skipReason != null) {
136150
if (ctx.currentTest) {
137151
// called from beforeEach hook

0 commit comments

Comments
 (0)