Skip to content

Commit efde03e

Browse files
chore(build): update download center config with new release info, instead of replacing it entirely when doing release - MONGOSH-1348 (#1549)
1 parent 1b138af commit efde03e

File tree

2 files changed

+264
-73
lines changed

2 files changed

+264
-73
lines changed
Lines changed: 202 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
import type { DownloadCenterConfig } from '@mongodb-js/dl-center/dist/download-center-config';
2+
import type { PackageInformationProvider } from '../packaging';
23
import { expect } from 'chai';
34
import sinon from 'ts-sinon';
45
import type { PackageVariant } from '../config';
56
import {
6-
createAndPublishDownloadCenterConfig,
7+
createVersionConfig,
78
createDownloadCenterConfig,
9+
getUpdatedDownloadCenterConfig,
10+
createAndPublishDownloadCenterConfig,
811
} from './config';
912

10-
describe('DownloadCenter config', function () {
11-
let config: DownloadCenterConfig;
12-
let packageInformation: any;
13-
14-
before(function () {
15-
packageInformation = (packageVariant: PackageVariant) => {
16-
const SHARED_OPENSSL_TAG =
17-
/-(openssl\d*)$/.exec(packageVariant)?.[1] || '';
18-
return {
19-
metadata: {
20-
version: '1.2.2',
21-
name: 'mongosh',
22-
rpmName:
23-
'mongodb-mongosh' +
24-
(SHARED_OPENSSL_TAG ? `-shared-${SHARED_OPENSSL_TAG}` : ''),
25-
debName:
26-
'mongodb-mongosh' +
27-
(SHARED_OPENSSL_TAG ? `-shared-${SHARED_OPENSSL_TAG}` : ''),
28-
},
29-
};
13+
const packageInformation = (version: string) =>
14+
((packageVariant: PackageVariant) => {
15+
const SHARED_OPENSSL_TAG = /-(openssl\d*)$/.exec(packageVariant)?.[1] || '';
16+
return {
17+
metadata: {
18+
version: version,
19+
name: 'mongosh',
20+
rpmName:
21+
'mongodb-mongosh' +
22+
(SHARED_OPENSSL_TAG ? `-shared-${SHARED_OPENSSL_TAG}` : ''),
23+
debName:
24+
'mongodb-mongosh' +
25+
(SHARED_OPENSSL_TAG ? `-shared-${SHARED_OPENSSL_TAG}` : ''),
26+
},
3027
};
31-
config = createDownloadCenterConfig(packageInformation);
32-
});
28+
}) as PackageInformationProvider;
3329

34-
describe('createDownloadCenterConfig', function () {
30+
describe('DownloadCenter config', function () {
31+
describe('createVersionConfig', function () {
3532
it('sets the version correctly', function () {
36-
expect(config.versions).to.have.length(1);
37-
const [version] = config.versions;
33+
const version = createVersionConfig(packageInformation('1.2.2'));
3834
expect(version._id).to.equal('1.2.2');
3935
expect(version.version).to.equal('1.2.2');
4036
});
4137

4238
it('has an artifact for darwin', function () {
43-
const [version] = config.versions;
39+
const version = createVersionConfig(packageInformation('1.2.2'));
4440
const platforms = version.platform.filter((p) => p.os === 'darwin');
4541
expect(platforms).to.have.length(2);
4642
expect(platforms[0].download_link).to.include(
@@ -52,7 +48,7 @@ describe('DownloadCenter config', function () {
5248
});
5349

5450
it('has an artifact for linux', function () {
55-
const [version] = config.versions;
51+
const version = createVersionConfig(packageInformation('1.2.2'));
5652
const platforms = version.platform.filter(
5753
(p) => p.os === 'linux' && p.arch === 'x64'
5854
);
@@ -65,7 +61,7 @@ describe('DownloadCenter config', function () {
6561
});
6662

6763
it('has an MSI and ZIP artifacts for windows', function () {
68-
const [version] = config.versions;
64+
const version = createVersionConfig(packageInformation('1.2.2'));
6965
const platforms = version.platform.filter(
7066
(p) => p.os === 'win32' || p.os === 'win32msi'
7167
);
@@ -77,7 +73,7 @@ describe('DownloadCenter config', function () {
7773
});
7874

7975
it('has an artifact for rpm', function () {
80-
const [version] = config.versions;
76+
const version = createVersionConfig(packageInformation('1.2.2'));
8177
const platforms = version.platform.filter(
8278
(p) => p.os === 'rpm' && p.arch === 'x64'
8379
);
@@ -90,7 +86,7 @@ describe('DownloadCenter config', function () {
9086
});
9187

9288
it('has an artifact for deb', function () {
93-
const [version] = config.versions;
89+
const version = createVersionConfig(packageInformation('1.2.2'));
9490
const platforms = version.platform.filter(
9591
(p) => p.os === 'deb' && p.arch === 'x64'
9692
);
@@ -103,35 +99,193 @@ describe('DownloadCenter config', function () {
10399
});
104100
});
105101

102+
describe('createDownloadCenterConfig', function () {
103+
it('creates a fresh download center config', function () {
104+
const getVersionConfig = sinon.stub().returns({ version: '1.2.2' });
105+
const config = createDownloadCenterConfig(getVersionConfig);
106+
expect(getVersionConfig).to.be.called;
107+
expect(config).deep.equal({
108+
versions: [{ version: '1.2.2' }],
109+
manual_link: 'https://docs.mongodb.org/manual/products/mongosh',
110+
release_notes_link: `https://github.com/mongodb-js/mongosh/releases/tag/v1.2.2`,
111+
previous_releases_link: '',
112+
development_releases_link: '',
113+
supported_browsers_link: '',
114+
tutorial_link: 'test',
115+
});
116+
});
117+
});
118+
119+
describe('getUpdatedDownloadCenterConfig', function () {
120+
context('when the current release is a new major bump', function () {
121+
it('adds a new entry for the current release to the download center config, while keeping the other major versions', function () {
122+
const getVersionConfig1x = sinon.stub().returns({ version: '1.2.2' });
123+
const getVersionConfig2x = sinon.stub().returns({ version: '2.0.0' });
124+
const existingDownloadCenterConfig =
125+
createDownloadCenterConfig(getVersionConfig1x);
126+
expect(existingDownloadCenterConfig.versions).to.have.lengthOf(1);
127+
128+
const updatedConfig = getUpdatedDownloadCenterConfig(
129+
existingDownloadCenterConfig,
130+
getVersionConfig2x
131+
);
132+
133+
expect(updatedConfig).to.deep.equal({
134+
versions: [{ version: '1.2.2' }, { version: '2.0.0' }],
135+
manual_link: 'https://docs.mongodb.org/manual/products/mongosh',
136+
release_notes_link: `https://github.com/mongodb-js/mongosh/releases/tag/v2.0.0`, // Release notes link will point to the current release being made
137+
previous_releases_link: '',
138+
development_releases_link: '',
139+
supported_browsers_link: '',
140+
tutorial_link: 'test',
141+
});
142+
});
143+
});
144+
145+
context(
146+
'when the current release is a minor/patch bump to one of earlier released major versions',
147+
function () {
148+
it('replaces the earlier released major version with the current minor/patch bump, while keeping the other major versions', function () {
149+
const getVersionConfig1x = sinon.stub().returns({ version: '1.2.2' });
150+
const getVersionConfig2x = sinon.stub().returns({ version: '2.0.0' });
151+
const getVersionConfig21 = sinon.stub().returns({ version: '2.1.0' });
152+
const existingDownloadCenterConfig =
153+
createDownloadCenterConfig(getVersionConfig1x);
154+
155+
const configWith2x = getUpdatedDownloadCenterConfig(
156+
existingDownloadCenterConfig,
157+
getVersionConfig2x
158+
);
159+
160+
const configWith21x = getUpdatedDownloadCenterConfig(
161+
configWith2x,
162+
getVersionConfig21
163+
);
164+
165+
expect(configWith21x).to.deep.equal({
166+
versions: [{ version: '1.2.2' }, { version: '2.1.0' }],
167+
manual_link: 'https://docs.mongodb.org/manual/products/mongosh',
168+
release_notes_link: `https://github.com/mongodb-js/mongosh/releases/tag/v2.1.0`, // Release notes link will point to the current release being made
169+
previous_releases_link: '',
170+
development_releases_link: '',
171+
supported_browsers_link: '',
172+
tutorial_link: 'test',
173+
});
174+
});
175+
}
176+
);
177+
});
178+
106179
describe('createAndPublishDownloadCenterConfig', function () {
107180
let dlCenter: sinon.SinonStub;
108181
let uploadConfig: sinon.SinonStub;
182+
let downloadConfig: sinon.SinonStub;
109183

110184
beforeEach(function () {
111185
uploadConfig = sinon.stub();
186+
downloadConfig = sinon.stub();
112187
dlCenter = sinon.stub();
113188

114-
dlCenter.returns({ uploadConfig });
189+
dlCenter.returns({ downloadConfig, uploadConfig });
115190
});
116191

117-
it('publishes the configuration', async function () {
118-
await createAndPublishDownloadCenterConfig(
119-
packageInformation,
120-
'accessKey',
121-
'secretKey',
122-
false,
123-
dlCenter as any
124-
);
192+
context('when a configuration does not exist', function () {
193+
it('publishes the created configuration', async function () {
194+
await createAndPublishDownloadCenterConfig(
195+
packageInformation('1.2.2'),
196+
'accessKey',
197+
'secretKey',
198+
false,
199+
dlCenter as any
200+
);
201+
202+
expect(dlCenter).to.have.been.calledWith({
203+
bucket: 'info-mongodb-com',
204+
accessKeyId: 'accessKey',
205+
secretAccessKey: 'secretKey',
206+
});
125207

126-
expect(dlCenter).to.have.been.calledWith({
127-
bucket: 'info-mongodb-com',
128-
accessKeyId: 'accessKey',
129-
secretAccessKey: 'secretKey',
208+
expect(uploadConfig).to.be.calledOnce;
209+
210+
const [uploadKey, uploadedConfig] = uploadConfig.lastCall.args;
211+
expect(uploadKey).to.equal('com-download-center/mongosh.json');
212+
213+
// Versions have platform info as well which we already verify in
214+
// createVersionConfig specs hence trimming it down here
215+
uploadedConfig.versions = (
216+
uploadedConfig as DownloadCenterConfig
217+
).versions.map((version) => ({
218+
...version,
219+
platform: [],
220+
}));
221+
222+
expect(uploadedConfig).to.deep.equal({
223+
versions: [{ _id: '1.2.2', version: '1.2.2', platform: [] }],
224+
manual_link: 'https://docs.mongodb.org/manual/products/mongosh',
225+
release_notes_link:
226+
'https://github.com/mongodb-js/mongosh/releases/tag/v1.2.2',
227+
previous_releases_link: '',
228+
development_releases_link: '',
229+
supported_browsers_link: '',
230+
tutorial_link: 'test',
231+
});
232+
});
233+
});
234+
235+
context('when a configuration exists already', function () {
236+
it('publishes an updated version of the existing configuration', async function () {
237+
downloadConfig.returns(
238+
createDownloadCenterConfig(
239+
sinon.stub().returns({
240+
_id: '1.2.2',
241+
version: '1.2.2',
242+
platform: [],
243+
})
244+
)
245+
);
246+
247+
await createAndPublishDownloadCenterConfig(
248+
packageInformation('2.0.0'),
249+
'accessKey',
250+
'secretKey',
251+
false,
252+
dlCenter as any
253+
);
254+
255+
expect(dlCenter).to.have.been.calledWith({
256+
bucket: 'info-mongodb-com',
257+
accessKeyId: 'accessKey',
258+
secretAccessKey: 'secretKey',
259+
});
260+
261+
expect(uploadConfig).to.be.calledOnce;
262+
263+
const [uploadKey, uploadedConfig] = uploadConfig.lastCall.args;
264+
expect(uploadKey).to.equal('com-download-center/mongosh.json');
265+
266+
// Versions have platform info as well which we already verify in
267+
// createVersionConfig specs hence trimming it down here
268+
uploadedConfig.versions = (
269+
uploadedConfig as DownloadCenterConfig
270+
).versions.map((version) => ({
271+
...version,
272+
platform: [],
273+
}));
274+
275+
expect(uploadedConfig).to.deep.equal({
276+
versions: [
277+
{ _id: '1.2.2', version: '1.2.2', platform: [] },
278+
{ _id: '2.0.0', version: '2.0.0', platform: [] },
279+
],
280+
manual_link: 'https://docs.mongodb.org/manual/products/mongosh',
281+
release_notes_link:
282+
'https://github.com/mongodb-js/mongosh/releases/tag/v2.0.0',
283+
previous_releases_link: '',
284+
development_releases_link: '',
285+
supported_browsers_link: '',
286+
tutorial_link: 'test',
287+
});
130288
});
131-
expect(uploadConfig).to.have.been.calledWith(
132-
'com-download-center/mongosh.json',
133-
createDownloadCenterConfig(packageInformation)
134-
);
135289
});
136290
});
137291
});

0 commit comments

Comments
 (0)