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:
parent
72ae7173c2
commit
827cb8a886
@ -72,6 +72,9 @@
|
||||
"<rootDir>/src/jest.setup.ts",
|
||||
"jest-canvas-mock"
|
||||
],
|
||||
"setupFilesAfterEnv": [
|
||||
"<rootDir>/src/jest-after-env.setup.ts"
|
||||
],
|
||||
"globals": {
|
||||
"ts-jest": {
|
||||
"isolatedModules": true
|
||||
|
||||
@ -294,8 +294,10 @@ export interface CephfsSource {
|
||||
secretRef?: SecretReference;
|
||||
/**
|
||||
* Whether the filesystem is used as readOnly.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
readOnly: boolean;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
export interface CinderSource {
|
||||
|
||||
5
src/jest-after-env.setup.ts
Normal file
5
src/jest-after-env.setup.ts
Normal 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";
|
||||
@ -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>
|
||||
`;
|
||||
@ -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");
|
||||
});
|
||||
});
|
||||
@ -10,7 +10,7 @@ import type { VolumeVariantComponent } from "../variant-helpers";
|
||||
import { LocalRef } from "../variant-helpers";
|
||||
|
||||
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">
|
||||
<ul>
|
||||
@ -39,7 +39,7 @@ export const CephFs: VolumeVariantComponent<"cephfs"> = (
|
||||
</DrawerItem>
|
||||
)
|
||||
}
|
||||
<DrawerItem name="Readonly">
|
||||
<DrawerItem name="Readonly" data-testid="cephfs-readonly">
|
||||
{readOnly.toString()}
|
||||
</DrawerItem>
|
||||
</>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user