Skip to content

Commit

Permalink
Add test in case of multiple deployable repos
Browse files Browse the repository at this point in the history
  • Loading branch information
rayangler committed Oct 11, 2023
1 parent c0f4f9c commit eb3f83f
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,19 @@ export const getRepoBranchesEntry = async (project: project, branch = ''): Promi

const cursor = db.collection('docsets').aggregate(aggregationPipeline);
const res = (await cursor.toArray()) as unknown as ReposBranchesDocument[];
const returnedEntry = res[0];

if (res.length > 1) {
console.warn(
`Expected 1 deployable repo for docset with project "${project}", but found ${res.length} instead. Defaulting to first found: "${returnedEntry.repoName}".`
);
}

// if not already set, set cache value for repo_branches
if (!internals[project]) {
internals[project] = res[0];
internals[project] = returnedEntry;
}
return res[0];
return returnedEntry;
} catch (e) {
console.error(`Error while getting repo branches entry: ${e}`);
throw e;
Expand Down
30 changes: 30 additions & 0 deletions modules/persistence/tests/data/docsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,35 @@
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
},
{
"_id": "6500937d24fcc731b4735d00",
"project": "multiple-deployables",
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"directories": {
"snooty_toml": "/docs"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"repos": ["6526fe0d17c4f50e837e419f", "6526fe0d17c4f50e837e420f"],
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
}
]
102 changes: 102 additions & 0 deletions modules/persistence/tests/data/repos_branches.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,107 @@
"directories": {
"snooty_toml": "/docs"
}
},
{
"_id": "6526fe0d17c4f50e837e419f",
"repoName": "docs-multiple-deployables-1",
"branches": [
{
"name": "v5.0",
"publishOriginalBranchName": true,
"active": true,
"aliases": [
"stable"
],
"gitBranchName": "v5.0",
"isStableBranch": false,
"urlAliases": [
"stable"
],
"urlSlug": "stable",
"versionSelectorLabel": "v5.0",
"buildsWithSnooty": true,
"id": "634991b6246409bf0cc5116b"
}
],
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"project": "multiple-deployables",
"internalOnly": false,
"prodDeployable": true,
"directories": {
"snooty_toml": "/docs-multiple-deployables-1"
}
},
{
"_id": "6526fe0d17c4f50e837e420f",
"repoName": "docs-multiple-deployables-2",
"branches": [
{
"name": "v5.0",
"publishOriginalBranchName": true,
"active": true,
"aliases": [
"stable"
],
"gitBranchName": "v5.0",
"isStableBranch": false,
"urlAliases": [
"stable"
],
"urlSlug": "stable",
"versionSelectorLabel": "v5.0",
"buildsWithSnooty": true,
"id": "634991b6246409bf0cc5116c"
}
],
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"project": "multiple-deployables",
"internalOnly": false,
"prodDeployable": true,
"directories": {
"snooty_toml": "/docs-multiple-deployables-2"
}
}
]
14 changes: 14 additions & 0 deletions modules/persistence/tests/metadata/associated_products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe('associated_products module', () => {
// Non-deployable repo example should have only 1 branch
expect(res.branches.length).toBeGreaterThan(1);
});

it('should leave a warning when more than one docset was found', async () => {
let msg = '';
const mockedWarn = jest.spyOn(global.console, 'warn').mockImplementationOnce((e) => {
msg = e;
});
const expectedFirstRepoName = 'docs-multiple-deployables-1';
const res = await _getRepoBranchesEntry('multiple-deployables');
expect(console.warn).toBeCalledTimes(1);
expect(msg.includes(expectedFirstRepoName)).toBeTruthy();
expect(res.prodDeployable).toBeTruthy();
expect(res.repoName).toEqual(expectedFirstRepoName);
mockedWarn.mockReset();
});
});

describe('getAllAssociatedRepoBranchesEntries', () => {
Expand Down

0 comments on commit eb3f83f

Please sign in to comment.