Add no more than 1000 items to a list plus tests
This commit is contained in:
@@ -165,8 +165,12 @@ export class DbConfigStore extends DisposableObject {
|
||||
...new Set(parent.repositories),
|
||||
...new Set(repoNwoList),
|
||||
]);
|
||||
parent.repositories = [...newRepositoriesList];
|
||||
|
||||
if (newRepositoriesList.size > 1000) {
|
||||
parent.repositories = [...Array.from(newRepositoriesList).slice(0, 1000)];
|
||||
} else {
|
||||
parent.repositories = [...newRepositoriesList];
|
||||
}
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -241,6 +241,80 @@ describe("db config store", () => {
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should add unique remote repositories to the correct list", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "list1",
|
||||
repositories: ["owner/repo1"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
expect(
|
||||
configStore.getConfig().value.databases.variantAnalysis
|
||||
.repositoryLists[0],
|
||||
).toEqual({
|
||||
name: "list1",
|
||||
repositories: ["owner/repo1"],
|
||||
});
|
||||
|
||||
// Add
|
||||
await configStore.addRemoteReposToList(
|
||||
["owner/repo1", "owner/repo2"],
|
||||
"list1",
|
||||
);
|
||||
|
||||
// Read the config file
|
||||
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
|
||||
|
||||
// Check that the config file has been updated
|
||||
const updatedRemoteDbs = updatedDbConfig.databases.variantAnalysis;
|
||||
expect(updatedRemoteDbs.repositories).toHaveLength(0);
|
||||
expect(updatedRemoteDbs.repositoryLists).toHaveLength(1);
|
||||
expect(updatedRemoteDbs.repositoryLists[0]).toEqual({
|
||||
name: "list1",
|
||||
repositories: ["owner/repo1", "owner/repo2"],
|
||||
});
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should add no more than 1000 repositories to a list", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "list1",
|
||||
repositories: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Add
|
||||
await configStore.addRemoteReposToList(
|
||||
[...Array(1001).keys()].map((i) => `owner/db${i}`),
|
||||
"list1",
|
||||
);
|
||||
|
||||
// Read the config file
|
||||
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
|
||||
|
||||
// Check that the config file has been updated
|
||||
const updatedRemoteDbs = updatedDbConfig.databases.variantAnalysis;
|
||||
expect(updatedRemoteDbs.repositories).toHaveLength(0);
|
||||
expect(updatedRemoteDbs.repositoryLists).toHaveLength(1);
|
||||
expect(updatedRemoteDbs.repositoryLists[0].repositories).toHaveLength(
|
||||
1000,
|
||||
);
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should add a remote owner", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig();
|
||||
|
||||
Reference in New Issue
Block a user