|
1 | 1 | import { describe, it, expect, vi, beforeAll } from "vitest" |
2 | 2 | import { screen, within } from "@testing-library/react" |
3 | 3 | import { Route, Routes } from "react-router" |
4 | | -import { K8sClient, type K8sList } from "@cozystack/k8s-client" |
| 4 | +import { K8sClient, K8sApiError, type K8sList } from "@cozystack/k8s-client" |
5 | 5 | import { StorageClassUsagePage } from "./StorageClassUsagePage.tsx" |
6 | 6 | import { TenantProvider } from "../lib/tenant-provider.tsx" |
7 | 7 | import { renderWithK8sProvider } from "../test-utils/render.tsx" |
@@ -50,6 +50,17 @@ function makeClient(pvcs: unknown[], appDefs: unknown[] = []): K8sClient { |
50 | 50 | return client |
51 | 51 | } |
52 | 52 |
|
| 53 | +// Only the PVC list fails. Rejecting every list would render the same notice |
| 54 | +// no matter which request broke, so the test could not tell them apart. |
| 55 | +function makeFailingClient(error: Error): K8sClient { |
| 56 | + const client = new K8sClient() |
| 57 | + vi.spyOn(client, "list").mockImplementation(async (_g, _v, plural) => { |
| 58 | + if (plural === "persistentvolumeclaims") throw error |
| 59 | + return { apiVersion: "v1", kind: `${plural}List`, metadata: {}, items: [] } as K8sList<unknown> |
| 60 | + }) |
| 61 | + return client |
| 62 | +} |
| 63 | + |
53 | 64 | function renderPage(client: K8sClient, sc: string) { |
54 | 65 | return renderWithK8sProvider( |
55 | 66 | <TenantProvider> |
@@ -116,6 +127,22 @@ describe("StorageClassUsagePage", () => { |
116 | 127 | expect(await screen.findByText(/no tenant workloads use/i)).toBeInTheDocument() |
117 | 128 | }) |
118 | 129 |
|
| 130 | + it("shows a permission notice when the PVC list is forbidden", async () => { |
| 131 | + const client = makeFailingClient(new K8sApiError(403, { message: "forbidden" })) |
| 132 | + renderPage(client, "replicated") |
| 133 | + expect( |
| 134 | + await screen.findByText(/you do not have permission to view persistent volume claims/i), |
| 135 | + ).toBeInTheDocument() |
| 136 | + }) |
| 137 | + |
| 138 | + it("shows a failure notice when the PVC list errors", async () => { |
| 139 | + const client = makeFailingClient(new K8sApiError(500, { message: "boom" })) |
| 140 | + renderPage(client, "replicated") |
| 141 | + expect( |
| 142 | + await screen.findByText(/failed to load persistent volume claims: boom/i), |
| 143 | + ).toBeInTheDocument() |
| 144 | + }) |
| 145 | + |
119 | 146 | it("renders the storage class as the heading", async () => { |
120 | 147 | const client = makeClient([]) |
121 | 148 | renderPage(client, "replicated") |
|
0 commit comments