From 827cb8a886ee875476ccd88934d2aa8fa32ba4de Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 30 May 2022 08:01:08 -0700 Subject: [PATCH] Fix crash in (#5501) --- package.json | 3 + src/common/k8s-api/endpoints/pod.api.ts | 4 +- src/jest-after-env.setup.ts | 5 + .../__snapshots__/ceph-fs.test.tsx.snap | 229 ++++++++++++++++++ .../variants/__tests__/ceph-fs.test.tsx | 116 +++++++++ .../details/volumes/variants/ceph-fs.tsx | 4 +- 6 files changed, 358 insertions(+), 3 deletions(-) create mode 100644 src/jest-after-env.setup.ts create mode 100644 src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/__snapshots__/ceph-fs.test.tsx.snap create mode 100644 src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/ceph-fs.test.tsx diff --git a/package.json b/package.json index 610ee7d886..9b4896ae81 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,9 @@ "/src/jest.setup.ts", "jest-canvas-mock" ], + "setupFilesAfterEnv": [ + "/src/jest-after-env.setup.ts" + ], "globals": { "ts-jest": { "isolatedModules": true diff --git a/src/common/k8s-api/endpoints/pod.api.ts b/src/common/k8s-api/endpoints/pod.api.ts index 8e3aa51559..fbacf4fb07 100644 --- a/src/common/k8s-api/endpoints/pod.api.ts +++ b/src/common/k8s-api/endpoints/pod.api.ts @@ -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 { diff --git a/src/jest-after-env.setup.ts b/src/jest-after-env.setup.ts new file mode 100644 index 0000000000..b9ee36c4cf --- /dev/null +++ b/src/jest-after-env.setup.ts @@ -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"; diff --git a/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/__snapshots__/ceph-fs.test.tsx.snap b/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/__snapshots__/ceph-fs.test.tsx.snap new file mode 100644 index 0000000000..627b2fb1a3 --- /dev/null +++ b/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/__snapshots__/ceph-fs.test.tsx.snap @@ -0,0 +1,229 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render 'false' for Readonly when false is provided 1`] = ` +
+
+ + Monitors + + +
    + +
+
+ + Mount Path + + + / + +
+
+ + Username + + + admin + +
+
+ + Secret Filepath + + + /etc/ceph/user.secret + +
+
+ + Readonly + + + false + +
+
+`; + +exports[` should render 'false' for Readonly when not provided 1`] = ` +
+
+ + Monitors + + +
    + +
+
+ + Mount Path + + + / + +
+
+ + Username + + + admin + +
+
+ + Secret Filepath + + + /etc/ceph/user.secret + +
+
+ + Readonly + + + false + +
+
+`; + +exports[` should render 'true' for Readonly when true is provided 1`] = ` +
+
+ + Monitors + + +
    + +
+
+ + Mount Path + + + / + +
+
+ + Username + + + admin + +
+
+ + Secret Filepath + + + /etc/ceph/user.secret + +
+
+ + Readonly + + + true + +
+
+`; diff --git a/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/ceph-fs.test.tsx b/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/ceph-fs.test.tsx new file mode 100644 index 0000000000..5555332328 --- /dev/null +++ b/src/renderer/components/+workloads-pods/details/volumes/variants/__tests__/ceph-fs.test.tsx @@ -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("", () => { + 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(( + + )); + + 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(( + + )); + + 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(( + + )); + + expect(result.container).toMatchSnapshot(); + expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("true"); + }); +}); diff --git a/src/renderer/components/+workloads-pods/details/volumes/variants/ceph-fs.tsx b/src/renderer/components/+workloads-pods/details/volumes/variants/ceph-fs.tsx index 0b44e7d355..a723f7be92 100644 --- a/src/renderer/components/+workloads-pods/details/volumes/variants/ceph-fs.tsx +++ b/src/renderer/components/+workloads-pods/details/volumes/variants/ceph-fs.tsx @@ -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 }}) => ( <>
    @@ -39,7 +39,7 @@ export const CephFs: VolumeVariantComponent<"cephfs"> = ( ) } - + {readOnly.toString()}