Provide a way to search for database items by name and language
We'll use this to check whether a database for our ql pack already exists.
While there are other methods that search for a database item by URI, we
only have a language chosen by the user and an nwo ("github/codeql").
So let's introduce a way to search for the db based on the information we
have.
This commit is contained in:
@@ -897,6 +897,20 @@ export class DatabaseManager extends DisposableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public async digForDatabaseItem(
|
||||
language: string,
|
||||
databaseNwo: string,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const dbItems = this.databaseItems || [];
|
||||
const dbs = dbItems.filter(
|
||||
(db) => db.language === language && db.name === databaseNwo,
|
||||
);
|
||||
if (dbs.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return dbs[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the workspace folder that corresponds to the source archive of `item`
|
||||
* if there is one, and -1 otherwise.
|
||||
|
||||
@@ -785,6 +785,39 @@ describe("local databases", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("digForDatabaseItem", () => {
|
||||
describe("when the item exists", () => {
|
||||
it("should return the database item", async () => {
|
||||
const mockDbItem = createMockDB();
|
||||
|
||||
await (databaseManager as any).addDatabaseItem(
|
||||
{} as ProgressCallback,
|
||||
{} as CancellationToken,
|
||||
mockDbItem,
|
||||
);
|
||||
|
||||
const databaseItem = await databaseManager.digForDatabaseItem(
|
||||
mockDbItem.language,
|
||||
mockDbItem.name,
|
||||
);
|
||||
|
||||
expect(databaseItem!.language).toEqual(mockDbItem.language);
|
||||
expect(databaseItem!.name).toEqual(mockDbItem.name);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the item doesn't exist", () => {
|
||||
it("should return nothing", async () => {
|
||||
const databaseItem = await databaseManager.digForDatabaseItem(
|
||||
"ruby",
|
||||
"mock-database-name",
|
||||
);
|
||||
|
||||
expect(databaseItem).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createMockDB(
|
||||
mockDbOptions = MOCK_DB_OPTIONS,
|
||||
// source archive location must be a real(-ish) location since
|
||||
|
||||
Reference in New Issue
Block a user