Skip to content

Commit 99c217b

Browse files
ensure compressor is always set
1 parent da46aea commit 99c217b

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

test/tools/runner/config.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as types from 'node:util/types';
44
import { expect } from 'chai';
55
import { type Context } from 'mocha';
66
import ConnectionString from 'mongodb-connection-string-url';
7+
import { type CompressorName } from 'mongodb-legacy';
78
import * as qs from 'querystring';
89
import * as url from 'url';
910

@@ -64,6 +65,19 @@ function convertToConnStringMap(obj: Record<string, any>) {
6465
return result.join(',');
6566
}
6667

68+
function getCompressor(compressor: string): CompressorName {
69+
switch (compressor) {
70+
case 'zstd':
71+
return 'zstd';
72+
case 'zlib':
73+
return 'zlib';
74+
case 'snappy':
75+
return 'snappy';
76+
default:
77+
return 'none';
78+
}
79+
}
80+
6781
export class TestConfiguration {
6882
version: string;
6983
clientSideEncryption: {
@@ -94,6 +108,7 @@ export class TestConfiguration {
94108
activeResources: number;
95109
isSrv: boolean;
96110
filters: Record<string, Filter>;
111+
compressor: CompressorName | null;
97112

98113
constructor(
99114
private uri: string,
@@ -111,6 +126,7 @@ export class TestConfiguration {
111126
this.buildInfo = context.buildInfo;
112127
this.serverApi = context.serverApi;
113128
this.isSrv = uri.indexOf('mongodb+srv') > -1;
129+
this.compressor = getCompressor(process.env.COMPRESSOR);
114130
this.options = {
115131
hosts,
116132
hostAddresses,
@@ -121,11 +137,11 @@ export class TestConfiguration {
121137
replicaSet: url.searchParams.get('replicaSet'),
122138
proxyURIParams: url.searchParams.get('proxyHost')
123139
? {
124-
proxyHost: url.searchParams.get('proxyHost'),
125-
proxyPort: Number(url.searchParams.get('proxyPort')),
126-
proxyUsername: url.searchParams.get('proxyUsername'),
127-
proxyPassword: url.searchParams.get('proxyPassword')
128-
}
140+
proxyHost: url.searchParams.get('proxyHost'),
141+
proxyPort: Number(url.searchParams.get('proxyPort')),
142+
proxyUsername: url.searchParams.get('proxyUsername'),
143+
proxyPassword: url.searchParams.get('proxyPassword')
144+
}
129145
: undefined
130146
};
131147
if (url.username) {
@@ -200,7 +216,13 @@ export class TestConfiguration {
200216
}
201217

202218
newClient(urlOrQueryOptions?: string | Record<string, any>, serverOptions?: MongoClientOptions) {
203-
serverOptions = Object.assign({}, getEnvironmentalOptions(), serverOptions);
219+
serverOptions = Object.assign(
220+
<MongoClientOptions>{
221+
compressors: this.compressor
222+
},
223+
getEnvironmentalOptions(),
224+
serverOptions
225+
);
204226

205227
if (this.loggingEnabled && !Object.hasOwn(serverOptions, 'mongodbLogPath')) {
206228
serverOptions = this.setupLogging(serverOptions);
@@ -314,12 +336,14 @@ export class TestConfiguration {
314336
authSource?: string;
315337
authMechanism?: string;
316338
authMechanismProperties?: Record<string, any>;
339+
compressors?: CompressorName;
317340
}
318341
) {
319342
options = {
320343
db: this.options.db,
321344
replicaSet: this.options.replicaSet,
322345
proxyURIParams: this.options.proxyURIParams,
346+
compressors: this.compressor,
323347
...options
324348
};
325349

0 commit comments

Comments
 (0)