1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix crash in <CephFs /> (#5501)

This commit is contained in:
Sebastian Malton 2022-05-30 08:01:08 -07:00 committed by GitHub
parent 72ae7173c2
commit 827cb8a886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 358 additions and 3 deletions

View File

@ -72,6 +72,9 @@
"<rootDir>/src/jest.setup.ts", "<rootDir>/src/jest.setup.ts",
"jest-canvas-mock" "jest-canvas-mock"
], ],
"setupFilesAfterEnv": [
"<rootDir>/src/jest-after-env.setup.ts"
],
"globals": { "globals": {
"ts-jest": { "ts-jest": {
"isolatedModules": true "isolatedModules": true

View File

@ -294,8 +294,10 @@ export interface CephfsSource {
secretRef?: SecretReference; secretRef?: SecretReference;
/** /**
* Whether the filesystem is used as readOnly. * Whether the filesystem is used as readOnly.
*
* @default false
*/ */
readOnly: boolean; readOnly?: boolean;
} }
export interface CinderSource { export interface CinderSource {

View File

@ -0,0 +1,5 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import "@testing-library/jest-dom/extend-expect";

View File

@ -0,0 +1,229 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<CephFs /> should render 'false' for Readonly when false is provided 1`] = `
<div>
<div
class="DrawerItem"
>
<span
class="name"
>
Monitors
</span>
<span
class="value"
>
<ul />
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Mount Path
</span>
<span
class="value"
>
/
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Username
</span>
<span
class="value"
>
admin
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Secret Filepath
</span>
<span
class="value"
>
/etc/ceph/user.secret
</span>
</div>
<div
class="DrawerItem"
data-testid="cephfs-readonly"
>
<span
class="name"
>
Readonly
</span>
<span
class="value"
>
false
</span>
</div>
</div>
`;
exports[`<CephFs /> should render 'false' for Readonly when not provided 1`] = `
<div>
<div
class="DrawerItem"
>
<span
class="name"
>
Monitors
</span>
<span
class="value"
>
<ul />
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Mount Path
</span>
<span
class="value"
>
/
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Username
</span>
<span
class="value"
>
admin
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Secret Filepath
</span>
<span
class="value"
>
/etc/ceph/user.secret
</span>
</div>
<div
class="DrawerItem"
data-testid="cephfs-readonly"
>
<span
class="name"
>
Readonly
</span>
<span
class="value"
>
false
</span>
</div>
</div>
`;
exports[`<CephFs /> should render 'true' for Readonly when true is provided 1`] = `
<div>
<div
class="DrawerItem"
>
<span
class="name"
>
Monitors
</span>
<span
class="value"
>
<ul />
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Mount Path
</span>
<span
class="value"
>
/
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Username
</span>
<span
class="value"
>
admin
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Secret Filepath
</span>
<span
class="value"
>
/etc/ceph/user.secret
</span>
</div>
<div
class="DrawerItem"
data-testid="cephfs-readonly"
>
<span
class="name"
>
Readonly
</span>
<span
class="value"
>
true
</span>
</div>
</div>
`;

View File

@ -0,0 +1,116 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { render } from "@testing-library/react";
import React from "react";
import type { CephfsSource } from "../../../../../../../common/k8s-api/endpoints";
import { Pod } from "../../../../../../../common/k8s-api/endpoints";
import { CephFs } from "../ceph-fs";
describe("<CephFs />", () => {
it("should render 'false' for Readonly when not provided", () => {
const cephfsName = "my-ceph";
const cephfsVolume: CephfsSource = {
monitors: [],
};
const pod = new Pod({
apiVersion: "v1",
kind: "Pod",
metadata: {
name: "my-pod",
namespace: "default",
resourceVersion: "1",
uid: "123",
selfLink: "/api/v1/pod/default/my-pod",
},
spec: {
volumes: [{
name: cephfsName,
cephfs: cephfsVolume,
}],
},
});
const result = render((
<CephFs
pod={pod}
variant={cephfsVolume}
volumeName={cephfsName}
/>
));
expect(result.container).toMatchSnapshot();
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("false");
});
it("should render 'false' for Readonly when false is provided", () => {
const cephfsName = "my-ceph";
const cephfsVolume: CephfsSource = {
monitors: [],
readOnly: false,
};
const pod = new Pod({
apiVersion: "v1",
kind: "Pod",
metadata: {
name: "my-pod",
namespace: "default",
resourceVersion: "1",
uid: "123",
selfLink: "/api/v1/pod/default/my-pod",
},
spec: {
volumes: [{
name: cephfsName,
cephfs: cephfsVolume,
}],
},
});
const result = render((
<CephFs
pod={pod}
variant={cephfsVolume}
volumeName={cephfsName}
/>
));
expect(result.container).toMatchSnapshot();
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("false");
});
it("should render 'true' for Readonly when true is provided", () => {
const cephfsName = "my-ceph";
const cephfsVolume: CephfsSource = {
monitors: [],
readOnly: true,
};
const pod = new Pod({
apiVersion: "v1",
kind: "Pod",
metadata: {
name: "my-pod",
namespace: "default",
resourceVersion: "1",
uid: "123",
selfLink: "/api/v1/pod/default/my-pod",
},
spec: {
volumes: [{
name: cephfsName,
cephfs: cephfsVolume,
}],
},
});
const result = render((
<CephFs
pod={pod}
variant={cephfsVolume}
volumeName={cephfsName}
/>
));
expect(result.container).toMatchSnapshot();
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("true");
});
});

View File

@ -10,7 +10,7 @@ import type { VolumeVariantComponent } from "../variant-helpers";
import { LocalRef } from "../variant-helpers"; import { LocalRef } from "../variant-helpers";
export const CephFs: VolumeVariantComponent<"cephfs"> = ( export const CephFs: VolumeVariantComponent<"cephfs"> = (
({ pod, variant: { monitors, path = "/", user = "admin", secretFile = "/etc/ceph/user.secret", secretRef, readOnly }}) => ( ({ pod, variant: { monitors, path = "/", user = "admin", secretFile = "/etc/ceph/user.secret", secretRef, readOnly = false }}) => (
<> <>
<DrawerItem name="Monitors"> <DrawerItem name="Monitors">
<ul> <ul>
@ -39,7 +39,7 @@ export const CephFs: VolumeVariantComponent<"cephfs"> = (
</DrawerItem> </DrawerItem>
) )
} }
<DrawerItem name="Readonly"> <DrawerItem name="Readonly" data-testid="cephfs-readonly">
{readOnly.toString()} {readOnly.toString()}
</DrawerItem> </DrawerItem>
</> </>