-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #540 from joseivanlopez/storage-issues
Add storage issues
- Loading branch information
Showing
32 changed files
with
1,111 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) [2023] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
// @ts-check | ||
|
||
/** | ||
* @typedef {object} ClientsIssues | ||
* @property {import ("~/client/mixins").Issue[]} storage - Issues from storage client | ||
*/ | ||
|
||
/** | ||
* Client for managing all issues, independently on the service owning the issues | ||
*/ | ||
class IssuesClient { | ||
/** | ||
* @param {object} clients - Clients managing issues | ||
* @param {import ("~/client/storage").StorageClient} clients.storage | ||
*/ | ||
constructor(clients) { | ||
this.clients = clients; | ||
} | ||
|
||
/** | ||
* Get issues from all clients managing issues | ||
* | ||
* @returns {Promise<ClientsIssues>} | ||
*/ | ||
async getAll() { | ||
const storage = await this.clients.storage.getIssues(); | ||
|
||
return { storage }; | ||
} | ||
|
||
/** | ||
* Checks whether there is some error | ||
* | ||
* @returns {Promise<boolean>} | ||
*/ | ||
async any() { | ||
const clientsIssues = await this.getAll(); | ||
const issues = Object.values(clientsIssues).flat(); | ||
|
||
return issues.length > 0; | ||
} | ||
|
||
/** | ||
* Registers a callback for each service to be executed when its issues change | ||
* | ||
* @param {import ("~/client/mixins").IssuesHandler} handler - callback function | ||
* @return {import ("./dbus").RemoveFn} function to disable the callback | ||
*/ | ||
onIssuesChange(handler) { | ||
const unsubscribeCallbacks = []; | ||
unsubscribeCallbacks.push(this.clients.storage.onIssuesChange(handler)); | ||
|
||
return () => { unsubscribeCallbacks.forEach(cb => cb()) }; | ||
} | ||
} | ||
|
||
export { IssuesClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) [2023] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
// @ts-check | ||
|
||
import { IssuesClient } from "./issues"; | ||
import { StorageClient } from "./storage"; | ||
|
||
const storageIssues = [ | ||
{ description: "Storage issue 1", severity: "error", details: "", source: "" }, | ||
{ description: "Storage issue 2", severity: "warn", details: "", source: "" }, | ||
{ description: "Storage issue 3", severity: "error", details: "", source: "" } | ||
]; | ||
|
||
const issues = { | ||
storage: [] | ||
}; | ||
|
||
jest.spyOn(StorageClient.prototype, 'getIssues').mockImplementation(async () => issues.storage); | ||
jest.spyOn(StorageClient.prototype, 'onIssuesChange'); | ||
|
||
const clientsWithIssues = { | ||
storage: new StorageClient() | ||
}; | ||
|
||
describe("#getAll", () => { | ||
beforeEach(() => { | ||
issues.storage = storageIssues; | ||
}); | ||
|
||
it("returns all the storage issues", async () => { | ||
const client = new IssuesClient(clientsWithIssues); | ||
|
||
const { storage } = await client.getAll(); | ||
expect(storage).toEqual(expect.arrayContaining(storageIssues)); | ||
}); | ||
}); | ||
|
||
describe("#any", () => { | ||
describe("if there are storage issues", () => { | ||
beforeEach(() => { | ||
issues.storage = storageIssues; | ||
}); | ||
|
||
it("returns true", async () => { | ||
const client = new IssuesClient(clientsWithIssues); | ||
|
||
const result = await client.any(); | ||
expect(result).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe("if there are no issues", () => { | ||
beforeEach(() => { | ||
issues.storage = []; | ||
}); | ||
|
||
it("returns false", async () => { | ||
const client = new IssuesClient(clientsWithIssues); | ||
|
||
const result = await client.any(); | ||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#onIssuesChange", () => { | ||
it("subscribes to changes in storage issues", () => { | ||
const client = new IssuesClient(clientsWithIssues); | ||
|
||
const handler = jest.fn(); | ||
client.onIssuesChange(handler); | ||
|
||
expect(clientsWithIssues.storage.onIssuesChange).toHaveBeenCalledWith(handler); | ||
}); | ||
}); |
Oops, something went wrong.